Skip to content

Commit cc69fe3

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-8732
Main's desktopStatusViewport (#32854) now picks when status remeasures a desktop tab; it runs under the 250 ms status deadline with the last measured viewport as the fallback. The test resizes the frame so status measures again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents ace4fd8 + 8a38c63 commit cc69fe3

75 files changed

Lines changed: 2204 additions & 485 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/preview/GuestProtocol.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export const ANNOTATION_THEME_CHANNEL = "preview:annotation-theme";
66
export const ANNOTATION_SEND_ENABLED_CHANNEL = "preview:annotation-send-enabled";
77
export const HUMAN_INPUT_CHANNEL = "preview:human-input";
88
export const MOUSE_NAVIGATE_CHANNEL = "preview:mouse-navigate";
9+
// Sent to the hosting <webview> element (ipc-message). The web app mirrors this
10+
// literal in HostedBrowserWebview because it cannot import from the desktop app.
11+
export const POINTER_DOWN_HOST_CHANNEL = "preview:pointer-down";
912
export const PAGE_UNHANDLED_SHORTCUT_CHANNEL = "preview:page-unhandled-shortcut";
1013
export const RECORDING_CURSOR_CHANNEL = "preview:recording-cursor";
1114
export const RECORDING_POINTER_CHANNEL = "preview:recording-pointer";

‎apps/desktop/src/preview/PickPreload.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
ELEMENT_PICKED_CHANNEL,
4141
HUMAN_INPUT_CHANNEL,
4242
MOUSE_NAVIGATE_CHANNEL,
43+
POINTER_DOWN_HOST_CHANNEL,
4344
PAGE_UNHANDLED_SHORTCUT_CHANNEL,
4445
RECORDING_CURSOR_CHANNEL,
4546
RECORDING_POINTER_CHANNEL,
@@ -193,6 +194,9 @@ const applyAnnotationTheme = (
193194

194195
const reportHumanPointerInput = (event: PointerEvent): void => {
195196
if (!event.isTrusted) return;
197+
// The guest does not always take focus on a click, so the host's webview
198+
// `focus` event can't be relied on to dismiss open menus and popovers.
199+
ipcRenderer.sendToHost(POINTER_DOWN_HOST_CHANNEL);
196200
ipcRenderer.send(HUMAN_INPUT_CHANNEL, {
197201
kind: "pointer",
198202
x: event.clientX,

‎apps/mobile/src/features/pull-requests/pullRequestActions.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export const MERGE_METHODS = {
3333
description: "Keep the commits and add a merge commit.",
3434
},
3535
rebase: { title: "Rebase and merge", description: "Add the commits without a merge commit." },
36+
"fast-forward": {
37+
title: "Fast-forward merge",
38+
description: "Add the commits as they are. Needs the branch to contain the base.",
39+
},
3640
} as const satisfies Record<PullRequestMergeMethod, { title: string; description: string }>;
3741

3842
export function pullRequestActionLabel(

‎apps/mobile/src/features/threads/new-task-flow-provider.test.tsx‎

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EnvironmentRegistry } from "@t3tools/client-runtime/connection";
44
import { createEnvironmentSubscriptionAtomFamily } from "@t3tools/client-runtime/state/runtime";
55
import {
66
AuthFilesystemReadScope,
7+
DEFAULT_SERVER_SETTINGS,
78
EnvironmentId,
89
ProjectId,
910
type VcsListRefsResult,
@@ -32,6 +33,9 @@ const mocks = vi.hoisted(() => ({
3233
retargetDraft: vi.fn(),
3334
writeSettings: vi.fn(),
3435
writeText: vi.fn(),
36+
serverConfig: vi.fn(),
37+
openScratch: vi.fn(),
38+
prepareTriage: vi.fn(),
3539
}));
3640
vi.mock("../../state/atom-registry", () => ({
3741
appAtomRegistry: {
@@ -43,7 +47,7 @@ vi.mock("../../state/atom-registry", () => ({
4347
vi.mock("../../state/entities", () => ({
4448
useProjects: mocks.projects,
4549
useThreadShells: () => [],
46-
useEnvironmentServerConfig: () => null,
50+
useEnvironmentServerConfig: () => mocks.serverConfig() ?? null,
4751
useServerConfigs: () => new Map(),
4852
}));
4953
vi.mock("../../state/vcs", () => ({
@@ -66,7 +70,8 @@ vi.mock("../../state/project-grouping", () => ({
6670
useMobileProjectGroupingSettings: () => ({ sidebarProjectGroupingMode: "none" }),
6771
}));
6872
vi.mock("../../components/ui/Dialog", () => ({ alert: vi.fn() }));
69-
vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() }));
73+
vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => mocks.openScratch }));
74+
vi.mock("../triage/usePrepareTriage", () => ({ usePrepareTriage: () => mocks.prepareTriage }));
7075
vi.mock("../../state/use-remote-environment-registry", () => ({
7176
useSavedRemoteConnections: () => ({ savedConnectionsById: {} }),
7277
useRemoteConnectionStatus: () => ({ connectedEnvironments: [] }),
@@ -362,3 +367,78 @@ it("uses cached repository capability and branch defaults while offline", async
362367
expect(screen.current.draftKey).toBe(draftKey);
363368
expect(screen.current.selectedBranchName).toBe("main");
364369
});
370+
371+
const playbookPrompt = (machine: string) =>
372+
`Read [triage-playbook.md](/${machine}/triage-playbook.md) and follow it. `;
373+
374+
/** A triage draft on machine one's No project home; machine two opens its own. */
375+
async function renderTriageDraft(screen: ReturnType<typeof setup>) {
376+
mocks.serverConfig.mockReturnValue({
377+
scratchWorkspaceRoot: "/a",
378+
providers: [],
379+
settings: DEFAULT_SERVER_SETTINGS,
380+
});
381+
mocks.openScratch.mockResolvedValue({ _tag: "Success", value: screen.projects[2] });
382+
await screen.render(true);
383+
act(() => screen.current.setPrompt(`${playbookPrompt("one")}It is slow.`));
384+
}
385+
386+
it("takes a triage draft's session along when its machine changes", async () => {
387+
using screen = setup();
388+
await renderTriageDraft(screen);
389+
mocks.prepareTriage.mockResolvedValue({
390+
_tag: "Success",
391+
value: { prompt: playbookPrompt("two") },
392+
});
393+
394+
await act(async () => {
395+
await screen.current.switchEnvironment(EnvironmentId.make("two"));
396+
});
397+
398+
expect(screen.current.prompt).toBe(`${playbookPrompt("two")}It is slow.`);
399+
expect(screen.current.selectedProject).toEqual(screen.projects[2]);
400+
});
401+
402+
it.each([
403+
[
404+
"a project is picked",
405+
1,
406+
(flow: ReturnType<typeof useNewTaskFlow>, picked: EnvironmentProject) =>
407+
flow.setProject(picked),
408+
],
409+
[
410+
"a send starts and ends",
411+
0,
412+
(flow: ReturnType<typeof useNewTaskFlow>) => {
413+
flow.setSubmitting(true);
414+
flow.setSubmitting(false);
415+
},
416+
],
417+
] as const)(
418+
"leaves a triage draft alone when %s while its new machine prepares",
419+
async (_name, expectedProject, interrupt) => {
420+
using screen = setup();
421+
await renderTriageDraft(screen);
422+
let finishPreparing!: (result: unknown) => void;
423+
mocks.prepareTriage.mockReturnValue(
424+
new Promise((resolve) => {
425+
finishPreparing = resolve;
426+
}),
427+
);
428+
429+
let switching!: Promise<boolean>;
430+
act(() => {
431+
switching = screen.current.switchEnvironment(EnvironmentId.make("two"));
432+
});
433+
await act(async () => interrupt(screen.current, screen.projects[1]!));
434+
let switched = true;
435+
await act(async () => {
436+
finishPreparing({ _tag: "Success", value: { prompt: playbookPrompt("two") } });
437+
switched = await switching;
438+
});
439+
440+
expect(switched).toBe(false);
441+
expect(screen.current.prompt).toBe(`${playbookPrompt("one")}It is slow.`);
442+
expect(screen.current.selectedProject).toEqual(screen.projects[expectedProject]);
443+
},
444+
);

‎apps/mobile/src/features/threads/new-task-flow-provider.tsx‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
ThreadId,
2020
} from "@t3tools/contracts";
2121
import { threadContextsOutsideEnvironment } from "@t3tools/shared/composerContextReferences";
22+
import { isTriagePrompt, replaceTriagePlaybookLink } from "@t3tools/shared/triagePrompt";
2223
import * as Arr from "effect/Array";
2324
import { pipe } from "effect/Function";
2425

@@ -102,6 +103,7 @@ import {
102103
stampedEnvironmentProjectsLoading,
103104
updateNewTaskFlowState,
104105
} from "./new-task-flow-state";
106+
import { usePrepareTriage } from "../triage/usePrepareTriage";
105107
import { useEnvironmentShellReadiness } from "../../state/shell";
106108
import { useConnectionsReady, useWorkspaceEnvironments } from "../../state/workspace";
107109

@@ -589,6 +591,7 @@ export function NewTaskFlowProvider(
589591
};
590592

591593
const openScratch = useAtomCommand(projectEnvironment.openScratch, { reportFailure: false });
594+
const prepareTriage = usePrepareTriage();
592595
const [switchingToEnvironmentId, setSwitchingToEnvironmentId] = useState<EnvironmentId | null>(
593596
null,
594597
);
@@ -606,11 +609,27 @@ export function NewTaskFlowProvider(
606609
const request = {};
607610
latestSwitchRef.current = request;
608611
setSwitchingToEnvironmentId(environmentId);
609-
const result = await openScratch({ environmentId, input: {} });
612+
// A triage draft takes its session along: the playbook and context files
613+
// exist only on the machine that prepared them.
614+
const { draftKey, projectKey } = readFlow();
615+
const triage =
616+
draftKey !== null && isTriagePrompt(getComposerDraftSnapshot(draftKey).text)
617+
? await prepareTriage(environmentId)
618+
: null;
619+
const result =
620+
triage?._tag === "Failure" ? triage : await openScratch({ environmentId, input: {} });
610621
if (latestSwitchRef.current !== request) return false;
611622
latestSwitchRef.current = null;
612623
setSwitchingToEnvironmentId(null);
624+
// A project picked while this waited stands.
625+
if (readFlow().projectKey !== projectKey) return false;
613626
if (result._tag === "Success") {
627+
if (triage?._tag === "Success" && draftKey !== null && readFlow().draftKey === draftKey) {
628+
// Read now, so text typed while the machine prepared the session is kept.
629+
const text = getComposerDraftSnapshot(draftKey).text;
630+
const nextText = replaceTriagePlaybookLink(text, triage.value.prompt);
631+
if (nextText !== text) setComposerDraftText(draftKey, nextText);
632+
}
614633
setProject(result.value);
615634
return true;
616635
}
@@ -620,7 +639,9 @@ export function NewTaskFlowProvider(
620639
"Could not switch machine",
621640
error instanceof Error
622641
? error.message
623-
: "The folder for threads without a project could not be created.",
642+
: triage?._tag === "Failure"
643+
? "The server could not prepare triage."
644+
: "The folder for threads without a project could not be created.",
624645
);
625646
}
626647
return false;
@@ -884,7 +905,14 @@ export function NewTaskFlowProvider(
884905
appendAttachments,
885906
removeAttachment,
886907
clearAttachments,
887-
setSubmitting: (value: boolean) => updateFlow({ submitting: value }),
908+
setSubmitting: (value: boolean) => {
909+
// A send takes the draft as it is, so a machine switch still waiting is dropped.
910+
if (value) {
911+
latestSwitchRef.current = null;
912+
setSwitchingToEnvironmentId(null);
913+
}
914+
updateFlow({ submitting: value });
915+
},
888916
loadBranches,
889917
setRuntimeMode,
890918
setSelectedModelOptions,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { EnvironmentId } from "@t3tools/contracts";
2+
import Constants from "expo-constants";
3+
4+
import { authClientMetadata } from "../../lib/authClientMetadata";
5+
import { serverEnvironment } from "../../state/server";
6+
import { useAtomCommand } from "../../state/use-atom-command";
7+
8+
/**
9+
* Asks a machine to prepare a triage session. The result carries the prompt
10+
* that links its playbook; the caller reports a failure.
11+
*/
12+
export function usePrepareTriage() {
13+
const prepare = useAtomCommand(serverEnvironment.prepareTriage, { reportFailure: false });
14+
return (environmentId: EnvironmentId) =>
15+
prepare({
16+
environmentId,
17+
input: { client: authClientMetadata(Constants.expoConfig?.version) },
18+
});
19+
}

‎apps/mobile/src/features/triage/useStartTriage.ts‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ import {
66
import type { EnvironmentId } from "@t3tools/contracts";
77
import { useNavigation } from "@react-navigation/native";
88
import * as Clipboard from "expo-clipboard";
9-
import Constants from "expo-constants";
109

1110
import * as Dialog from "../../components/ui/Dialog";
12-
import { authClientMetadata } from "../../lib/authClientMetadata";
1311
import { projectEnvironment } from "../../state/projects";
14-
import { serverEnvironment } from "../../state/server";
1512
import { useAtomCommand } from "../../state/use-atom-command";
1613
import {
1714
createNewTaskDraft,
1815
setComposerDraftText,
1916
waitForComposerDraftsLoaded,
2017
} from "../../state/use-composer-drafts";
2118
import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspaceDetail";
19+
import { usePrepareTriage } from "./usePrepareTriage";
2220

2321
const CLI_COMMAND = "npx t3 triage";
2422

@@ -29,7 +27,7 @@ const CLI_COMMAND = "npx t3 triage";
2927
export function useStartTriage() {
3028
const navigation = useNavigation();
3129
const selectDetail = useSelectWorkspaceDetail();
32-
const prepare = useAtomCommand(serverEnvironment.prepareTriage, { reportFailure: false });
30+
const prepare = usePrepareTriage();
3331
const openScratch = useAtomCommand(projectEnvironment.openScratch, { reportFailure: false });
3432

3533
const fail = (message: string) =>
@@ -77,10 +75,7 @@ export function useStartTriage() {
7775
}
7876
return;
7977
}
80-
const prepared = await prepare({
81-
environmentId,
82-
input: { client: authClientMetadata(Constants.expoConfig?.version) },
83-
});
78+
const prepared = await prepare(environmentId);
8479
if (prepared._tag === "Failure") {
8580
if (!isAtomCommandInterrupted(prepared)) {
8681
pipe(

‎apps/mobile/src/persistence/mobile-preferences.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
PullRequestListFilters,
1212
PullRequestListState,
1313
type ProviderInstanceId,
14-
type PullRequestMergeMethod,
14+
PullRequestMergeMethod,
1515
type SidebarProjectGroupingMode,
1616
} from "@t3tools/contracts";
1717
import { ToolCallVisibility } from "@t3tools/contracts/settings";
@@ -174,6 +174,7 @@ export class MobilePreferencesStore extends Context.Service<
174174
>()("@t3tools/mobile/persistence/mobile-preferences/MobilePreferencesStore") {}
175175

176176
const isToolCallVisibility = Schema.is(ToolCallVisibility);
177+
const isPullRequestMergeMethod = Schema.is(PullRequestMergeMethod);
177178

178179
function sanitizePreferences(parsed: Preferences): Preferences {
179180
const preferences: {
@@ -232,11 +233,7 @@ function sanitizePreferences(parsed: Preferences): Preferences {
232233
preferences.pullRequestHideTestFiles = parsed.pullRequestHideTestFiles;
233234
}
234235

235-
if (
236-
parsed.pullRequestMergeMethod === "squash" ||
237-
parsed.pullRequestMergeMethod === "merge" ||
238-
parsed.pullRequestMergeMethod === "rebase"
239-
) {
236+
if (isPullRequestMergeMethod(parsed.pullRequestMergeMethod)) {
240237
preferences.pullRequestMergeMethod = parsed.pullRequestMergeMethod;
241238
}
242239

0 commit comments

Comments
 (0)