Skip to content

Commit b29d2f9

Browse files
fix(web): carry viewed access mode into new pull-request drafts
Minting a PR draft from ChatView only consulted last-used and the machine default, so a supervised thread could land on full-access when last-used was empty. Prefer the composer override, then the viewed thread mode. Co-authored-by: Cursor <[email protected]>
1 parent 8f8bf59 commit b29d2f9

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

‎apps/web/src/components/ChatView.logic.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
resolveComposerInteractionMode,
5454
resolveComposerProviderSelection,
5555
resolveDraftPromotionNavigationTarget,
56+
resolveNewPullRequestDraftRuntimeMode,
5657
observeProactivePanelUserChoice,
5758
resolveProactiveTurnDiffAction,
5859
resolveThreadMetadataUpdateForNextTurn,
@@ -259,6 +260,24 @@ describe("proactive panels", () => {
259260
expect(shouldOpenProactivePullRequest("project:repo:42", null)).toBe(false);
260261
});
261262

263+
it("carries the viewed thread mode into a new pull-request draft", () => {
264+
expect(
265+
resolveNewPullRequestDraftRuntimeMode({
266+
viewedThreadRuntimeMode: "approval-required",
267+
lastUsedRuntimeMode: null,
268+
configuredRuntimeMode: "full-access",
269+
}),
270+
).toBe("approval-required");
271+
expect(
272+
resolveNewPullRequestDraftRuntimeMode({
273+
composerRuntimeMode: "auto-accept-edits",
274+
viewedThreadRuntimeMode: "approval-required",
275+
lastUsedRuntimeMode: "full-access",
276+
configuredRuntimeMode: "full-access",
277+
}),
278+
).toBe("auto-accept-edits");
279+
});
280+
262281
it("follows a changed server PR link without replacing an unrelated open panel", () => {
263282
const previous = {
264283
projectId: ProjectId.make("project-1"),

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
type ProviderInteractionMode,
1212
ProviderDriverKind,
1313
type ProviderInstanceId,
14+
type RuntimeMode,
1415
type ServerProvider,
1516
type ScopedProjectRef,
1617
type ScopedThreadRef,
@@ -24,6 +25,7 @@ import {
2425
type AtomCommandResult,
2526
} from "@t3tools/client-runtime/state/runtime";
2627
import { videoMimeType } from "@t3tools/shared/video";
28+
import { resolveNewThreadRuntimeMode } from "@t3tools/shared/runtimeMode";
2729
import {
2830
appendCodexArtifactTemplateUsePrompt,
2931
codexArtifactTemplateUsePrompt,
@@ -629,6 +631,24 @@ export interface PullRequestDialogState {
629631
key: number;
630632
}
631633

634+
/**
635+
* Access mode for a freshly minted pull-request draft opened from ChatView.
636+
* Composer overrides win over the viewed thread/session, then last-used and
637+
* the machine default — same carry precedence as new-thread creation.
638+
*/
639+
export function resolveNewPullRequestDraftRuntimeMode(sources: {
640+
readonly composerRuntimeMode?: RuntimeMode | null;
641+
readonly viewedThreadRuntimeMode?: RuntimeMode | null;
642+
readonly lastUsedRuntimeMode?: RuntimeMode | null;
643+
readonly configuredRuntimeMode?: RuntimeMode | null;
644+
}): RuntimeMode {
645+
return resolveNewThreadRuntimeMode({
646+
carryRuntimeMode: sources.composerRuntimeMode ?? sources.viewedThreadRuntimeMode ?? null,
647+
lastUsedRuntimeMode: sources.lastUsedRuntimeMode,
648+
configuredRuntimeMode: sources.configuredRuntimeMode,
649+
});
650+
}
651+
632652
export function readFileAsDataUrl(file: File): Promise<string> {
633653
return new Promise((resolve, reject) => {
634654
const reader = new FileReader();

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ import {
258258
preventTerminalCloseShortcut,
259259
} from "../lib/terminalCloseShortcut";
260260
import { resolveNewDraftStartFromOrigin } from "../lib/chatThreadActions";
261-
import { resolveNewThreadRuntimeMode } from "@t3tools/shared/runtimeMode";
262261
import {
263262
derivePhysicalProjectKey,
264263
deriveLogicalProjectKeyFromSettings,
@@ -410,6 +409,7 @@ import {
410409
resolveComposerInteractionMode,
411410
resolveComposerProviderSelection,
412411
resolveDraftHeroState,
412+
resolveNewPullRequestDraftRuntimeMode,
413413
observeProactivePanelUserChoice,
414414
resolveProactiveTurnDiffAction,
415415
resolveThreadMetadataUpdateForNextTurn,
@@ -2268,7 +2268,9 @@ export default function ChatView(props: ChatViewProps) {
22682268

22692269
const nextDraftId = newDraftId();
22702270
const nextThreadId = newThreadId();
2271-
const resolvedRuntimeMode = resolveNewThreadRuntimeMode({
2271+
const resolvedRuntimeMode = resolveNewPullRequestDraftRuntimeMode({
2272+
composerRuntimeMode,
2273+
viewedThreadRuntimeMode: activeThread?.runtimeMode,
22722274
lastUsedRuntimeMode: getLastUsedRuntimeMode(logicalProjectKey),
22732275
configuredRuntimeMode: settings.defaultRuntimeMode,
22742276
});
@@ -2287,6 +2289,8 @@ export default function ChatView(props: ChatViewProps) {
22872289
},
22882290
[
22892291
activeProject,
2292+
activeThread?.runtimeMode,
2293+
composerRuntimeMode,
22902294
draftId,
22912295
getDraftSession,
22922296
getDraftSessionByLogicalProjectKey,

0 commit comments

Comments
 (0)