Skip to content

Commit 84f6370

Browse files
Merge remote-tracking branch 'origin/main' into voltcrash/fix-issue-29198
2 parents 49b6c89 + d8f3fef commit 84f6370

167 files changed

Lines changed: 5802 additions & 1562 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/backend/tailscaleEndpointProvider.test.ts‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { assert, describe, it } from "@effect/vitest";
22
import * as Effect from "effect/Effect";
33
import * as Layer from "effect/Layer";
4-
import { HttpClient } from "effect/http";
4+
import { HttpClient, HttpClientResponse } from "effect/http";
55
import { ChildProcessSpawner } from "effect/process";
66

77
import { resolveTailscaleAdvertisedEndpoints } from "./tailscaleEndpointProvider.ts";
@@ -79,4 +79,41 @@ describe("tailscale endpoint provider", () => {
7979
);
8080
}).pipe(Effect.provide(layerUnusedTailscaleExternalServices)),
8181
);
82+
83+
it.effect("offers Tailscale HTTPS only when Serve reaches this desktop's backend", () =>
84+
Effect.gen(function* () {
85+
const magicDnsStatus = (servedEnvironmentId: string) =>
86+
resolveTailscaleAdvertisedEndpoints({
87+
port: 3773,
88+
serveEnabled: true,
89+
networkInterfaces: {},
90+
statusJson: `{"Self":{"DNSName":"desktop.example.ts.net.","TailscaleIPs":[]}}`,
91+
}).pipe(
92+
Effect.map((endpoints) => endpoints.map((endpoint) => endpoint.status)),
93+
Effect.provideService(
94+
HttpClient.HttpClient,
95+
HttpClient.make((request) =>
96+
Effect.succeed(
97+
HttpClientResponse.fromWeb(
98+
request,
99+
Response.json({
100+
environmentId:
101+
new URL(request.url).hostname === "127.0.0.1"
102+
? "desktop-backend"
103+
: servedEnvironmentId,
104+
label: "T3 server",
105+
platform: { os: "linux", arch: "x64" },
106+
serverVersion: "0.1.9",
107+
capabilities: { repositoryIdentity: true },
108+
}),
109+
),
110+
),
111+
),
112+
),
113+
);
114+
115+
assert.deepEqual(yield* magicDnsStatus("desktop-backend"), ["available"]);
116+
assert.deepEqual(yield* magicDnsStatus("another-server"), ["unavailable"]);
117+
}).pipe(Effect.provide(layerUnusedTailscaleExternalServices)),
118+
);
82119
});

‎apps/desktop/src/backend/tailscaleEndpointProvider.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { createAdvertisedEndpoint } from "@t3tools/shared/advertisedEndpoint";
2-
import type { AdvertisedEndpoint, AdvertisedEndpointProvider } from "@t3tools/contracts";
2+
import {
3+
ExecutionEnvironmentDescriptor,
4+
type AdvertisedEndpoint,
5+
type AdvertisedEndpointProvider,
6+
} from "@t3tools/contracts";
37
import {
48
buildTailscaleHttpsBaseUrl,
59
isTailscaleIpv4Address,
@@ -11,6 +15,7 @@ import {
1115
import * as Effect from "effect/Effect";
1216
import * as Option from "effect/Option";
1317
import * as HttpClient from "effect/http/HttpClient";
18+
import * as HttpClientResponse from "effect/http/HttpClientResponse";
1419
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1520

1621
import type { NetworkInterfaces } from "./DesktopNetworkInterfaces.ts";
@@ -71,10 +76,20 @@ function resolveTailscaleIpAdvertisedEndpoints(input: {
7176
return endpoints;
7277
}
7378

79+
// The backend may run elsewhere (WSL), so ask it for its id instead of reading the state dir.
80+
const probeServesThisBackend = (localHttpUrl: string) => (baseUrl: string) =>
81+
HttpClient.get(new URL("/.well-known/t3/environment", localHttpUrl)).pipe(
82+
Effect.flatMap(HttpClientResponse.filterStatusOk),
83+
Effect.flatMap(HttpClientResponse.schemaBodyJson(ExecutionEnvironmentDescriptor)),
84+
Effect.flatMap(({ environmentId }) => probeTailscaleHttpsEndpoint({ baseUrl, environmentId })),
85+
Effect.orElseSucceed(() => false),
86+
);
87+
7488
const resolveTailscaleMagicDnsAdvertisedEndpoint = Effect.fn(
7589
"resolveTailscaleMagicDnsAdvertisedEndpoint",
7690
)(function* (input: {
7791
readonly dnsName: string | null;
92+
readonly localHttpUrl: string;
7893
readonly serveEnabled: boolean;
7994
readonly servePort?: number;
8095
readonly probe?: (baseUrl: string) => Effect.Effect<boolean, never, HttpClient.HttpClient>;
@@ -87,11 +102,7 @@ const resolveTailscaleMagicDnsAdvertisedEndpoint = Effect.fn(
87102
magicDnsName: input.dnsName,
88103
...(input.servePort === undefined ? {} : { servePort: input.servePort }),
89104
});
90-
const probe =
91-
input.probe?.(httpBaseUrl) ??
92-
probeTailscaleHttpsEndpoint({
93-
baseUrl: httpBaseUrl,
94-
});
105+
const probe = (input.probe ?? probeServesThisBackend(input.localHttpUrl))(httpBaseUrl);
95106
const isReachable = input.serveEnabled ? yield* probe : false;
96107

97108
return Option.some(
@@ -140,6 +151,7 @@ export const resolveTailscaleAdvertisedEndpoints = Effect.fn("resolveTailscaleAd
140151
const ipEndpoints = resolveTailscaleIpAdvertisedEndpoints({ ...input, status });
141152
const magicDnsEndpoint = yield* resolveTailscaleMagicDnsAdvertisedEndpoint({
142153
dnsName: status?.magicDnsName ?? null,
154+
localHttpUrl: `http://127.0.0.1:${input.port}`,
143155
serveEnabled: input.serveEnabled === true,
144156
...(input.servePort === undefined ? {} : { servePort: input.servePort }),
145157
...(input.probe === undefined ? {} : { probe: input.probe }),

‎apps/desktop/src/electron/ElectronShell.test.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,30 @@ describe("ElectronShell", () => {
5454
}).pipe(Effect.provide(ElectronShell.layer)),
5555
);
5656

57-
it.effect("opens only the bare Grok Bot launch link", () =>
57+
it.effect("opens only the Grok Bot prompt link", () =>
5858
Effect.gen(function* () {
5959
openExternalMock.mockResolvedValue(undefined);
6060

61+
const prompt = "grokbot://app/v1/prompt?text=Add%20the%20MCP%20server";
6162
const electronShell = yield* ElectronShell.ElectronShell;
6263
const results = yield* Effect.forEach(
63-
["grokbot://app", "grokbot://app/v1/prompt?id=bot&text=hi", "grokbot://"],
64+
[
65+
prompt,
66+
"grokbot://app",
67+
"grokbot://app/v1/prompt?id=bot&text=hi",
68+
"grokbot://app/v1/prompt?text=a&text=b",
69+
"grokbot://app/v1/other?text=hi",
70+
"grokbot://app/v1/prompt?text=hi#x",
71+
"grokbot://:secret@app/v1/prompt?text=hi",
72+
"grokbot://user@app/v1/prompt?text=hi",
73+
"grokbot://other/v1/prompt?text=hi",
74+
"other://app/v1/prompt?text=hi",
75+
],
6476
(url) => electronShell.openExternal(url),
6577
);
6678

67-
assert.deepEqual(results, [true, false, false]);
68-
assert.deepEqual(openExternalMock.mock.calls, [["grokbot://app"]]);
79+
assert.deepEqual(results, [true, ...Array<boolean>(9).fill(false)]);
80+
assert.deepEqual(openExternalMock.mock.calls, [[prompt]]);
6981
}).pipe(Effect.provide(ElectronShell.layer)),
7082
);
7183

‎apps/desktop/src/electron/ElectronShell.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@ const REMOTE_EDITOR_PROTOCOLS = new Set(
2121
}),
2222
);
2323

24-
// "Use T3 Code in another app" opens these apps (apps/web/src/components/mcp/mcpApps.ts). List
24+
// "Use T3 Code in another app" opens these apps (apps/web/src/components/mcp/mcpApps.ts). Match
2525
// each exact link shape the wizard sends, never a whole scheme.
26-
const APP_LAUNCH_URLS = new Set(["grokbot://app"]);
26+
const isAppLaunchUrl = (url: URL) =>
27+
url.protocol === "grokbot:" &&
28+
url.host === "app" &&
29+
url.pathname === "/v1/prompt" &&
30+
url.username.length === 0 &&
31+
url.password.length === 0 &&
32+
url.hash.length === 0 &&
33+
[...url.searchParams.keys()].join() === "text";
2734

2835
// Zed embeds [user@]host in the path; reject passwords and ports there.
2936
const ZED_SSH_PATHNAME = /^\/(?:[^/@:]+@)?[^/@:]+\/.*$/;
@@ -50,7 +57,7 @@ export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
5057
try {
5158
const url = new URL(rawUrl);
5259
return SAFE_WEB_PROTOCOLS.has(url.protocol) ||
53-
APP_LAUNCH_URLS.has(url.href) ||
60+
isAppLaunchUrl(url) ||
5461
isRemoteEditorUrl(url) ||
5562
isLocalEditorFileUrl(url)
5663
? Option.some(url.href)

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,25 @@ it("keeps the tool while typing a tool key in the comment", () => {
6262

6363
expect(document.documentElement.getAttribute("data-t3code-annotation-tool")).toBe("select");
6464
});
65+
66+
it("keeps comment keystrokes away from the page's capture-phase shortcuts", () => {
67+
const pageShortcut = vi.fn((event: KeyboardEvent) => event.preventDefault());
68+
window.addEventListener("keydown", pageShortcut, { capture: true });
69+
const shadowRoot = startAnnotation();
70+
const comment = shadowRoot.querySelector("textarea");
71+
if (!comment) throw new Error("comment textarea not found");
72+
73+
comment.focus();
74+
const space = new KeyboardEvent("keydown", {
75+
key: " ",
76+
code: "Space",
77+
bubbles: true,
78+
cancelable: true,
79+
composed: true,
80+
});
81+
comment.dispatchEvent(space);
82+
window.removeEventListener("keydown", pageShortcut, { capture: true });
83+
84+
expect(pageShortcut).not.toHaveBeenCalled();
85+
expect(space.defaultPrevented).toBe(false);
86+
});

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ interface AnnotationSession {
149149
teardown: (notifyMain: boolean) => void;
150150
applyTheme: (theme: DesktopPreviewAnnotationTheme) => void;
151151
setSendEnabled: (enabled: boolean) => void;
152+
handleOverlayKey: (event: KeyboardEvent) => void;
152153
}
153154

154155
let activeSession: AnnotationSession | null = null;
@@ -225,6 +226,18 @@ const reportUnhandledShortcut = (event: KeyboardEvent): void => {
225226

226227
window.addEventListener("keydown", reportUnhandledShortcut, true);
227228

229+
// Registered before page scripts so their capture listeners never see keys typed into the
230+
// overlay; the closed shadow root retargets those to the host, hiding that they edit text.
231+
const isolateOverlayKey = (event: KeyboardEvent): void => {
232+
if (!activeSession || !(event.target instanceof Element) || !isAnnotationNode(event.target))
233+
return;
234+
activeSession.handleOverlayKey(event);
235+
event.stopImmediatePropagation();
236+
};
237+
238+
for (const type of ["keydown", "keypress", "keyup"] as const)
239+
window.addEventListener(type, isolateOverlayKey, true);
240+
228241
const MOUSE_BUTTON_BACK = 3;
229242
const MOUSE_BUTTON_FORWARD = 4;
230243

@@ -1762,15 +1775,17 @@ function startAnnotation(
17621775
});
17631776
};
17641777
submit.addEventListener("click", () => submitAnnotation("attach"));
1765-
root.addEventListener("keydown", (event) => {
1778+
const handleOverlayKey = (event: KeyboardEvent): void => {
1779+
if (event.type === "keyup") onVoiceKeyUp(event);
1780+
if (event.type !== "keydown") return;
1781+
onKeyDown(event);
1782+
if (event.cancelBubble) return;
17661783
const submission =
1767-
event.target === comment ? resolveAnnotationSubmission(event, sendEnabled) : null;
1768-
// Bubble phase lets editor inputs handle events before hiding them from the page.
1769-
event.stopImmediatePropagation();
1784+
shadowRoot.activeElement === comment ? resolveAnnotationSubmission(event, sendEnabled) : null;
17701785
if (!submission) return;
17711786
event.preventDefault();
17721787
submitAnnotation(submission);
1773-
});
1788+
};
17741789

17751790
window.addEventListener("pointermove", onPointerMove, { capture: true, passive: false });
17761791
window.addEventListener("pointerdown", onPointerDown, { capture: true, passive: false });
@@ -1806,6 +1821,7 @@ function startAnnotation(
18061821
sendEnabled = enabled;
18071822
updateSendHint();
18081823
},
1824+
handleOverlayKey,
18091825
};
18101826
}
18111827

‎apps/mobile/src/features/files/filePath.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { describe, expect, it } from "vite-plus/test";
22

33
import {
44
fileRoutePathSegments,
5+
isAudioPreviewFile,
6+
isMarkdownPreviewFile,
57
needsWorkspaceFileContents,
68
resolveFileLinkPath,
79
resolveWorkspaceRelativeFilePath,
@@ -58,3 +60,14 @@ describe("needsWorkspaceFileContents", () => {
5860
expect(needsWorkspaceFileContents({ ...input, metadataKind: "directory" })).toBe(false);
5961
});
6062
});
63+
64+
describe("workspace preview classifiers", () => {
65+
it("treat # and ? as literal filename characters", () => {
66+
for (const path of ["notes/clip#1.wav", "notes/clip?1.wav", "notes#old/clip.wav"]) {
67+
expect(isAudioPreviewFile(path)).toBe(true);
68+
}
69+
for (const path of ["docs/draft#1.md", "docs/draft?1.md", "docs#old/draft.md"]) {
70+
expect(isMarkdownPreviewFile(path)).toBe(true);
71+
}
72+
});
73+
});

‎apps/mobile/src/features/files/filePath.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ export function isVideoPreviewFile(path: string): boolean {
100100
}
101101

102102
export function isAudioPreviewFile(path: string): boolean {
103-
return isWorkspaceAudioPreviewPath(path.split(/[?#]/, 1)[0] ?? "");
103+
return isWorkspaceAudioPreviewPath(path);
104104
}
105105

106106
export function isSvgImagePreviewFile(path: string): boolean {
107-
return /\.svg$/i.test(path.split(/[?#]/, 1)[0] ?? "");
107+
return /\.svg$/i.test(path);
108108
}
109109

110110
export function isMarkdownPreviewFile(path: string): boolean {
111-
return /\.(?:md|mdx)$/i.test(path.split(/[?#]/, 1)[0] ?? "");
111+
return /\.(?:md|mdx)$/i.test(path);
112112
}
113113

114114
export function needsWorkspaceFileContents(input: {

‎apps/mobile/src/features/home/useThreadListActions.test.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ProviderInstanceId,
88
RunId,
99
ThreadId,
10+
type ThreadTitleRegenerationOutcome,
1011
} from "@t3tools/contracts";
1112
import * as Cause from "effect/Cause";
1213
import { AsyncResult } from "effect/reactivity";
@@ -18,6 +19,7 @@ const state = vi.hoisted(() => ({
1819
dropBusy: false,
1920
holdingRows: false,
2021
failedAction: null as string | null,
22+
titleOutcome: null as ThreadTitleRegenerationOutcome | null,
2123
archivedRefreshes: [] as string[],
2224
scopes: new Map<string, Set<string>>(),
2325
shells: [] as EnvironmentThreadShell[],
@@ -141,6 +143,7 @@ vi.mock("../../state/threads", () => ({
141143
"reorderPin",
142144
"reorderActive",
143145
"updateMetadata",
146+
"regenerateTitle",
144147
].map((action) => [
145148
action,
146149
async (request: {
@@ -155,7 +158,7 @@ vi.mock("../../state/threads", () => ({
155158
if (action === state.failedAction)
156159
return AsyncResult.failure(Cause.fail(new Error("Server rejected action")));
157160
state.afterRequest?.();
158-
return AsyncResult.success(undefined);
161+
return AsyncResult.success(action === "regenerateTitle" ? state.titleOutcome : undefined);
159162
},
160163
]),
161164
),
@@ -186,12 +189,13 @@ const mutationCases = [
186189
["unsnoozeThread", "unsnooze"],
187190
["pinThread", "pin"],
188191
["unpinThread", "unpin"],
189-
["regenerateThreadTitle", "updateMetadata"],
192+
["regenerateThreadTitle", "regenerateTitle"],
190193
] as const;
191194

192195
beforeEach(() => {
193196
state.connectedEnvironmentIds = [primaryEnvironmentId, otherEnvironmentId];
194197
state.failedAction = null;
198+
state.titleOutcome = null;
195199
state.archivedRefreshes = [];
196200
state.pendingOrder = null;
197201
state.dropBusy = false;
@@ -214,6 +218,16 @@ afterEach(() => {
214218
vi.unstubAllEnvs();
215219
});
216220

221+
it("reports a failed title generation as unsuccessful and allows another request", async () => {
222+
const actions = useThreadListActions();
223+
const thread = makeThread();
224+
state.titleOutcome = { status: "failed", message: "Model unavailable" };
225+
expect(await actions.regenerateThreadTitle(thread)).toBe(false);
226+
227+
state.titleOutcome = { status: "renamed" };
228+
expect(await actions.regenerateThreadTitle(thread)).toBe(true);
229+
});
230+
217231
describe("thread list operation permissions", () => {
218232
it.each(mutationCases)(
219233
"%s rejects a retained callback after its environment loses permission",

0 commit comments

Comments
 (0)