Skip to content

Commit 9a9cb8d

Browse files
Merge remote-tracking branch 'origin/main' into fix/28880-diff-appearance-contrast
2 parents 8f5d4b5 + 977d613 commit 9a9cb8d

252 files changed

Lines changed: 10370 additions & 1725 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/app/DesktopObservability.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,27 @@ describe("DesktopObservability", () => {
281281
),
282282
);
283283

284+
it.effect("startup prunes only canonical rotation suffixes", () =>
285+
Effect.gen(function* () {
286+
const fileSystem = yield* FileSystem.FileSystem;
287+
const directory = yield* fileSystem.makeTempDirectoryScoped({
288+
prefix: "t3-desktop-rotating-prune-test-",
289+
});
290+
const filePath = `${directory}/server-child.log`;
291+
const retained = ["1", "3", "04", "4.0", "4e0", "0x4", "+4", "notes"];
292+
for (const suffix of [...retained, "4", "50"]) {
293+
yield* fileSystem.writeFileString(`${filePath}.${suffix}`, suffix);
294+
}
295+
296+
yield* DesktopObservability.makeRotatingLogFileWriter({ filePath, maxFiles: 3 });
297+
298+
assert.deepEqual(
299+
(yield* fileSystem.readDirectory(directory)).sort(),
300+
retained.map((suffix) => `server-child.log.${suffix}`).sort(),
301+
);
302+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
303+
);
304+
284305
it.effect("stops every export when the OpenTelemetry SDK is disabled", () => {
285306
const requests: Array<ExportedRequest> = [];
286307
return Effect.gen(function* () {

‎apps/desktop/src/app/DesktopObservability.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,10 @@ export const makeRotatingLogFileWriter = Effect.fn("makeRotatingLogFileWriter")(
263263
const entries = yield* fileSystem.readDirectory(directory).pipe(Effect.orElseSucceed(() => []));
264264
for (const entry of entries) {
265265
if (!entry.startsWith(`${baseName}.`)) continue;
266-
const suffix = Number(entry.slice(baseName.length + 1));
267-
if (!Number.isInteger(suffix) || suffix <= maxFiles) continue;
266+
const suffixText = entry.slice(baseName.length + 1);
267+
const suffix = Number(suffixText);
268+
if (!Number.isInteger(suffix) || String(suffix) !== suffixText || suffix <= maxFiles)
269+
continue;
268270
yield* fileSystem.remove(path.join(directory, entry), { force: true }).pipe(Effect.ignore);
269271
}
270272
});

‎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/desktop/src/updates/releaseNotes.test.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,20 @@ describe("normalizeDesktopUpdateReleaseNotes", () => {
241241
});
242242
});
243243

244-
it("does not throw on out-of-range numeric entities and keeps the literal", () => {
244+
it("keeps unsupported entities literal, including out-of-range and Object.prototype names", () => {
245245
const result = normalizeDesktopUpdateReleaseNotes(
246-
"- Broken entity &#9999999999;",
246+
"- Broken entity &#9999999999;\n- Mentions &constructor; and &toString;",
247247
"1.0.0",
248248
"latest",
249249
);
250250
expect(result).toEqual({
251-
releaseNotes: [{ version: "1.0.0", items: ["Broken entity &#9999999999;"], totalItems: 1 }],
251+
releaseNotes: [
252+
{
253+
version: "1.0.0",
254+
items: ["Mentions &constructor; and &toString;", "Broken entity &#9999999999;"],
255+
totalItems: 2,
256+
},
257+
],
252258
omittedReleaseCount: 0,
253259
});
254260
});

‎apps/desktop/src/updates/releaseNotes.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ const MAX_RELEASE_NOTE_GROUPS = 6;
2020
const MAX_RELEASE_NOTE_ITEMS_PER_GROUP = 8;
2121
const MAX_RELEASE_NOTE_ITEM_LENGTH = 220;
2222

23-
const HTML_ENTITY_REPLACEMENTS: Readonly<Record<string, string>> = {
24-
amp: "&",
25-
apos: "'",
26-
gt: ">",
27-
lt: "<",
28-
nbsp: " ",
29-
quot: '"',
30-
};
23+
const HTML_ENTITY_REPLACEMENTS: ReadonlyMap<string, string> = new Map([
24+
["amp", "&"],
25+
["apos", "'"],
26+
["gt", ">"],
27+
["lt", "<"],
28+
["nbsp", " "],
29+
["quot", '"'],
30+
]);
3131

3232
function decodeCodePoint(codePoint: number, entity: string): string {
3333
if (!Number.isInteger(codePoint) || codePoint < 0 || codePoint > 0x10ffff) {
@@ -37,7 +37,7 @@ function decodeCodePoint(codePoint: number, entity: string): string {
3737
}
3838

3939
function decodeHtmlEntity(entity: string): string {
40-
const named = HTML_ENTITY_REPLACEMENTS[entity];
40+
const named = HTML_ENTITY_REPLACEMENTS.get(entity);
4141
if (named) return named;
4242
if (entity.startsWith("#x")) {
4343
return decodeCodePoint(Number.parseInt(entity.slice(2), 16), entity);

0 commit comments

Comments
 (0)