Skip to content

Commit 2577cc3

Browse files
Merge remote-tracking branch 'origin/main' into fix/pr-27006-review-feedback
2 parents f256fe8 + e0d0fb3 commit 2577cc3

90 files changed

Lines changed: 2444 additions & 521 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/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",

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ export function useThreadListActions(): {
240240
const updateThreadMetadata = useAtomCommand(threadEnvironment.updateMetadata, {
241241
reportFailure: false,
242242
});
243+
const regenerateTitle = useAtomCommand(threadEnvironment.regenerateTitle, {
244+
reportFailure: false,
245+
});
243246
const snoozeInFlightThreadKeys = useRef(new Set<string>());
244247
const titleRegenerationInFlightThreadKeys = useRef(new Set<string>());
245248

@@ -529,9 +532,9 @@ export function useThreadListActions(): {
529532
titleRegenerationInFlightThreadKeys.current.add(key);
530533
selectionHaptic();
531534
const succeeded = await (async () => {
532-
const result = await updateThreadMetadata({
535+
const result = await regenerateTitle({
533536
environmentId: thread.environmentId,
534-
input: { threadId: thread.id, regenerateTitle: true },
537+
input: { threadId: thread.id },
535538
});
536539
if (result._tag === "Failure") {
537540
const error = Cause.squash(result.cause);
@@ -543,6 +546,13 @@ export function useThreadListActions(): {
543546
);
544547
return false;
545548
}
549+
if (result.value?.status === "failed") {
550+
Dialog.alert(
551+
"Could not regenerate title",
552+
result.value.message ?? "The thread title could not be regenerated.",
553+
);
554+
return false;
555+
}
546556
return true;
547557
})();
548558
titleRegenerationInFlightThreadKeys.current.delete(key);

‎apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ import { useScheduledTaskDestinationLabel, useScheduledTaskEditor } from "./sche
8787
import {
8888
discardScheduledTaskEditor,
8989
markScheduledTaskEditorSaved,
90-
scheduledTaskEditorSessionAtom,
9190
} from "./scheduled-task-editor-state";
92-
import { appAtomRegistry } from "../../state/atom-registry";
9391
import {
9492
formatNextScheduledTaskRun,
9593
formatScheduledTaskInterval,
@@ -519,8 +517,6 @@ function SettingsScheduledTaskEditorScreen({ title }: { readonly title: string }
519517
const voiceInput = useVoiceInputController({
520518
ownerKey,
521519
label: editor?.draft.title.trim() || title,
522-
subscribeToDraftChanges: (onChange) =>
523-
appAtomRegistry.subscribe(scheduledTaskEditorSessionAtom, onChange),
524520
selection,
525521
readDraftMessage: () => {
526522
const current = readEditor();

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,11 @@ import { armAgentAwarenessLiveActivityForLocalWork } from "../agent-awareness/re
5757
import { scopedThreadKey } from "../../lib/scopedEntities";
5858
import {
5959
getComposerDraftSnapshot,
60-
composerDraftsAtom,
6160
setComposerDraftText,
6261
composerContextImportsAtom,
6362
countComposerDraftAttachmentsAfterSelection,
6463
useComposerDraft,
6564
} from "../../state/use-composer-drafts";
66-
import { appAtomRegistry } from "../../state/atom-registry";
6765
import type { ComposerDocumentAttachment } from "../../lib/composerContext";
6866
import { useProject, useVisibleThreadShells } from "../../state/entities";
6967
import { useMentionableEnvironments } from "../../state/environments";
@@ -579,7 +577,6 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
579577
ownerKey: composerDraftKey,
580578
label: props.selectedThread.title || "Untitled thread",
581579
readDraftMessage: () => getComposerDraftSnapshot(composerDraftKey).text,
582-
subscribeToDraftChanges: (onChange) => appAtomRegistry.subscribe(composerDraftsAtom, onChange),
583580
selection: composerMenu.selection,
584581
onChangeDraftMessage: (text) => setComposerDraftText(composerDraftKey, text),
585582
onChangeSelection: composerMenu.onSelectionChange,

‎apps/mobile/src/features/voice-input/lazyVoiceRecorder.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ describe("createLazyVoiceRecorder", () => {
143143
ownerKey: "thread",
144144
text: "",
145145
selection: { start: 0, end: 0 },
146-
revision: 0,
147146
}),
148147
commitDraft: () => undefined,
149148
onStateChange: () => undefined,

‎apps/mobile/src/features/voice-input/useVoiceInputController.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export function useVoiceInputController(input: {
1515
readonly ownerKey: string | null;
1616
readonly label: string;
1717
readonly readDraftMessage: () => string | null;
18-
readonly subscribeToDraftChanges: (onChange: () => void) => () => void;
1918
readonly selection: ComposerEditorSelection;
2019
readonly disabled?: boolean;
2120
readonly onChangeDraftMessage: (value: string) => void;
@@ -58,7 +57,6 @@ export function useVoiceInputController(input: {
5857
}
5958
},
6059
captured.selection,
61-
captured.subscribeToDraftChanges,
6260
),
6361
label: captured.label,
6462
});

0 commit comments

Comments
 (0)