Skip to content

Commit 167729f

Browse files
authored
Merge pull request #94 from nullStack65/feat/native-0.1.10-sender-line-tailscale-default
feat: sender line in the thread hover card, Tailscale HTTPS on by default
2 parents 34b82d2 + 0c91eef commit 167729f

12 files changed

Lines changed: 209 additions & 48 deletions

‎apps/desktop/src/backend/DesktopServerExposure.test.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,27 @@ describe("DesktopServerExposure", () => {
181181
);
182182
});
183183

184+
it.effect("reads Tailscale by default, and never after Serve is turned off locally", () => {
185+
let statusReads = 0;
186+
return withHarness(
187+
lanNetworkInterfaces,
188+
Effect.gen(function* () {
189+
const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
190+
yield* serverExposure.configureFromSettings({ port: 4173 });
191+
yield* serverExposure.getAdvertisedEndpoints;
192+
assert.equal(statusReads, 1);
193+
194+
yield* serverExposure.setTailscaleServeEnabled({ enabled: false });
195+
yield* serverExposure.getAdvertisedEndpoints;
196+
assert.equal(statusReads, 1);
197+
}),
198+
{},
199+
layerMockSpawner("{}", () => {
200+
statusReads += 1;
201+
}),
202+
);
203+
});
204+
184205
it.effect("falls back to local-only without losing the requested network preference", () =>
185206
withHarness(
186207
emptyNetworkInterfaces,
@@ -253,7 +274,7 @@ describe("DesktopServerExposure", () => {
253274
mode: "network-accessible",
254275
endpointUrl: "http://192.168.1.20:4173",
255276
advertisedHost: "192.168.1.20",
256-
tailscaleServeEnabled: false,
277+
tailscaleServeEnabled: true,
257278
tailscaleServePort: 443,
258279
});
259280

‎apps/desktop/src/settings/DesktopAppSettings.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { assert, describe, it } from "@effect/vitest";
44
import * as Effect from "effect/Effect";
55
import * as FileSystem from "effect/FileSystem";
66
import * as Layer from "effect/Layer";
7+
import * as Option from "effect/Option";
78
import * as PlatformError from "effect/PlatformError";
89
import * as Schema from "effect/Schema";
910
import * as Tracer from "effect/Tracer";
@@ -295,6 +296,7 @@ describe("DesktopSettings", () => {
295296

296297
yield* settings.setMainWindowBounds({ x: -1200, y: 40, width: 400, height: 360 }, true);
297298
yield* settings.setServerExposureMode("network-accessible");
299+
yield* settings.setTailscaleServe({ enabled: false, port: Option.none() });
298300

299301
const persisted = yield* decodeDesktopSettingsPatch(
300302
yield* fileSystem.readFileString(environment.desktopSettingsPath),
@@ -303,6 +305,7 @@ describe("DesktopSettings", () => {
303305
mainWindowBounds: { x: -1200, y: 40, width: 400, height: 360 },
304306
mainWindowMaximized: true,
305307
serverExposureMode: "network-accessible",
308+
tailscaleServeEnabled: false,
306309
} satisfies typeof DesktopSettingsPatch.Type);
307310

308311
const restored = yield* Effect.gen(function* () {
@@ -311,6 +314,7 @@ describe("DesktopSettings", () => {
311314
}).pipe(Effect.provide(DesktopAppSettings.layer));
312315
assert.deepEqual(restored.mainWindowBounds, persisted.mainWindowBounds);
313316
assert.isTrue(restored.mainWindowMaximized);
317+
assert.isFalse(restored.tailscaleServeEnabled);
314318
}),
315319
),
316320
);
@@ -381,7 +385,8 @@ describe("DesktopSettings", () => {
381385
mainWindowBounds: null,
382386
mainWindowMaximized: false,
383387
serverExposureMode: "local-only",
384-
tailscaleServeEnabled: false,
388+
// A missing key reads as on; an off saved before it became the default left no key.
389+
tailscaleServeEnabled: true,
385390
tailscaleServePort: 443,
386391
updateChannel: "nightly",
387392
updateChannelConfiguredByUser: false,
@@ -410,7 +415,8 @@ describe("DesktopSettings", () => {
410415
mainWindowBounds: null,
411416
mainWindowMaximized: false,
412417
serverExposureMode: "local-only",
413-
tailscaleServeEnabled: false,
418+
// A missing key reads as on; an off saved before it became the default left no key.
419+
tailscaleServeEnabled: true,
414420
tailscaleServePort: 443,
415421
updateChannel: "latest",
416422
updateChannelConfiguredByUser: true,

‎apps/desktop/src/settings/DesktopAppSettings.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export const DEFAULT_DESKTOP_SETTINGS: DesktopSettings = {
7474
mainWindowBounds: null,
7575
mainWindowMaximized: false,
7676
serverExposureMode: "local-only",
77-
tailscaleServeEnabled: false,
77+
// Closura fleet default. Only an explicit off is stored; Serve stays inert without Tailscale.
78+
tailscaleServeEnabled: true,
7879
tailscaleServePort: DEFAULT_TAILSCALE_SERVE_PORT,
7980
updateChannel: "latest",
8081
updateChannelConfiguredByUser: false,
@@ -231,7 +232,7 @@ function normalizeDesktopSettingsDocument(
231232
mainWindowMaximized: mainWindowBounds !== null && parsed.mainWindowMaximized === true,
232233
serverExposureMode:
233234
parsed.serverExposureMode === "network-accessible" ? "network-accessible" : "local-only",
234-
tailscaleServeEnabled: parsed.tailscaleServeEnabled === true,
235+
tailscaleServeEnabled: parsed.tailscaleServeEnabled ?? defaultSettings.tailscaleServeEnabled,
235236
tailscaleServePort: normalizeTailscaleServePort(parsed.tailscaleServePort),
236237
updateChannel: updateChannelConfiguredByUser
237238
? Option.getOrElse(parsedUpdateChannel, () => defaultSettings.updateChannel)

‎apps/web/src/components/Sidebar.drag.browser.test.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ it("keeps focus in the search box when a click picks a search result", async ()
120120
projectDisplayName={null}
121121
environmentLabel={null}
122122
environmentMachine="server"
123+
senderLabel={null}
124+
senderByAgent={false}
123125
providerEntryByInstanceId={new Map()}
124126
isHighlighted={false}
125127
isRouteActive={false}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { SidebarThreadFilterMenu } from "./sidebar/SidebarThreadFilterMenu";
22
import { matchesThreadListFilter, threadListFilterOf } from "./sidebar/threadListFilter.logic";
33
import {
4+
launchingThreadIdOf,
45
resolveMachineOwners,
56
resolveThreadAttributions,
67
threadAttributionKey,
8+
threadSenderLine,
79
} from "@t3tools/client-runtime/state/thread-attribution";
810
import {
911
matchesOlderSettledGroup,
@@ -1138,6 +1140,19 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
11381140
const threadAttributions = resolveThreadAttributions(threads, machineOwners);
11391141
const attributionOf = (thread: Pick<EnvironmentThreadShell, "environmentId" | "id">) =>
11401142
threadAttributions.get(threadAttributionKey(thread)) ?? "unknown";
1143+
// Ids are unique across machines, and an agent often launches work on another one.
1144+
const threadTitleById = new Map<string, string>(
1145+
threads.map((thread) => [thread.id, thread.title]),
1146+
);
1147+
const senderLineOf = (thread: EnvironmentThreadShell) => {
1148+
const attribution = threadAttributions.get(threadAttributionKey(thread));
1149+
if (attribution === undefined) return null;
1150+
const launcherId = launchingThreadIdOf(thread);
1151+
return threadSenderLine(
1152+
attribution,
1153+
launcherId === null ? null : (threadTitleById.get(launcherId) ?? null),
1154+
);
1155+
};
11411156
// Search always looks across every inbox, sender and environment.
11421157
const listFilterApplies = threadSearchQuery.trim().length === 0;
11431158
const inboxThreads = listFilterApplies
@@ -3304,6 +3319,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
33043319
const threadKey = scopedThreadKey(
33053320
scopeThreadRef(thread.environmentId, thread.id),
33063321
);
3322+
const senderLine = senderLineOf(thread);
33073323
return (
33083324
<SidebarSearchResultRow
33093325
isSettled={settledThreadKeys.has(threadKey)}
@@ -3318,6 +3334,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
33183334
) ?? null
33193335
}
33203336
environmentLabel={environmentLabelById.get(thread.environmentId) ?? null}
3337+
senderLabel={senderLine?.label ?? null}
3338+
senderByAgent={senderLine?.byAgent ?? false}
33213339
environmentMachine={
33223340
environmentMachineById.get(thread.environmentId) ?? "server"
33233341
}
@@ -3452,6 +3470,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
34523470
: isCard
34533471
? "card"
34543472
: "slim";
3473+
const senderLine = senderLineOf(thread);
34553474
return (
34563475
<SortableThreadRow
34573476
key={threadKey}
@@ -3513,6 +3532,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
35133532
}
35143533
currentEnvironmentId={primaryEnvironmentId}
35153534
attribution={attributionOf(thread)}
3535+
senderLabel={senderLine?.label ?? null}
3536+
senderByAgent={senderLine?.byAgent ?? false}
35163537
environmentLabel={
35173538
environmentLabelById.get(thread.environmentId) ?? null
35183539
}

‎apps/web/src/components/settings/ConnectionsSettings.logic.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
resolveAccessEnvironmentId,
88
resolveTailscaleServeBaseUrl,
99
selectQrEndpointOption,
10+
tailscaleHttpsRow,
1011
togglePairingScopeSelection,
1112
} from "./ConnectionsSettings.logic";
1213

@@ -73,6 +74,24 @@ describe("resolveTailscaleServeBaseUrl", () => {
7374
});
7475
});
7576

77+
describe("tailscaleHttpsRow", () => {
78+
const url = "https://laptop.tail.ts.net";
79+
const on = { tailscaleServeEnabled: true } as const;
80+
const off = { tailscaleServeEnabled: false } as const;
81+
82+
it("follows the saved setting, not whether Serve answers", () => {
83+
expect(
84+
[
85+
tailscaleHttpsRow(on, { status: "available", httpBaseUrl: url }),
86+
tailscaleHttpsRow(on, { status: "unavailable", httpBaseUrl: url }),
87+
tailscaleHttpsRow(on, null),
88+
tailscaleHttpsRow(off, { status: "available", httpBaseUrl: url }),
89+
tailscaleHttpsRow(off, null),
90+
].map((row) => row.checked),
91+
).toEqual([true, true, true, false, false]);
92+
});
93+
});
94+
7695
const baseWslState: DesktopWslState = {
7796
enabled: false,
7897
distro: null,

‎apps/web/src/components/settings/ConnectionsSettings.logic.ts‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,31 @@ export function isQrShareableEndpoint(endpoint: AdvertisedEndpoint): boolean {
6161
return endpoint.status !== "unavailable" && endpoint.reachability !== "loopback";
6262
}
6363

64-
/** Desktop skips Tailscale probing until network/Serve is enabled to avoid macOS prompts; absence then
65-
* means unchecked. */
66-
export function missingTailscaleEndpointDescription(
67-
state: Pick<DesktopServerExposureState, "mode" | "tailscaleServeEnabled"> | null,
68-
): string {
69-
return state && state.mode !== "network-accessible" && !state.tailscaleServeEnabled
70-
? "Turn on Network access to detect Tailscale."
71-
: "Start Tailscale to set up HTTPS access through MagicDNS.";
64+
/**
65+
* The Tailscale HTTPS switch and its status line. Serve is on by default and does nothing until
66+
* Tailscale runs here, signed in with MagicDNS. Desktop skips Tailscale probing while Serve and
67+
* network access are off to avoid macOS prompts, so no endpoint then says nothing about Tailscale.
68+
*/
69+
export function tailscaleHttpsRow(
70+
state: Pick<DesktopServerExposureState, "tailscaleServeEnabled"> | null,
71+
endpoint: Pick<AdvertisedEndpoint, "status" | "httpBaseUrl"> | null,
72+
): { readonly checked: boolean; readonly description: string } {
73+
if (!state?.tailscaleServeEnabled) {
74+
return {
75+
checked: false,
76+
description: endpoint
77+
? `Off. Turn on to serve this backend at ${endpoint.httpBaseUrl}`
78+
: "Off. Turn on to serve this backend over Tailscale HTTPS.",
79+
};
80+
}
81+
return {
82+
checked: true,
83+
description: !endpoint
84+
? "On. Inactive until Tailscale runs here, signed in with MagicDNS."
85+
: endpoint.status === "available"
86+
? `On at ${endpoint.httpBaseUrl}`
87+
: `On, but ${endpoint.httpBaseUrl} doesn't answer. Tailscale Serve needs HTTPS certificates on the tailnet and its port free.`,
88+
};
7289
}
7390

7491
export function resolveTailscaleServeBaseUrl(

‎apps/web/src/components/settings/ConnectionsSettings.tsx‎

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
applyWslEnableSelection,
3232
connectDeviceName,
3333
isWslSettingsRowVisible,
34-
missingTailscaleEndpointDescription,
34+
tailscaleHttpsRow,
3535
resolveLocalVersionStatusLabel,
3636
resolveTailscaleServeBaseUrl,
3737
} from "./ConnectionsSettings.logic";
@@ -370,8 +370,10 @@ function ConnectionsSettingsContent({
370370
| { readonly kind: "wsl-only"; readonly nextValue: boolean };
371371
const [pendingWslChange, setPendingWslChange] = useState<PendingWslChange | null>(null);
372372
const isWslConfirmDialogOpen = pendingWslChange !== null;
373-
const [pendingTailscaleServeEndpoint, setPendingTailscaleServeEndpoint] =
374-
useState<AdvertisedEndpoint | null>(null);
373+
// Setup can start before Tailscale reports a MagicDNS name, so the endpoint may be null.
374+
const [pendingTailscaleServeSetup, setPendingTailscaleServeSetup] = useState<{
375+
readonly endpoint: AdvertisedEndpoint | null;
376+
} | null>(null);
375377
const [disableTailscaleServeDialogOpen, setDisableTailscaleServeDialogOpen] = useState(false);
376378
const [tailscaleServePortInput, setTailscaleServePortInput] = useState(
377379
String(DEFAULT_TAILSCALE_SERVE_PORT),
@@ -469,7 +471,7 @@ function ConnectionsSettingsContent({
469471
parsedTailscaleServePort <= 65_535;
470472

471473
const pendingTailscaleServeBaseUrl = resolveTailscaleServeBaseUrl(
472-
pendingTailscaleServeEndpoint,
474+
pendingTailscaleServeSetup?.endpoint ?? null,
473475
parsedTailscaleServePort,
474476
isTailscaleServePortValid,
475477
);
@@ -525,7 +527,7 @@ function ConnectionsSettingsContent({
525527
port: parsedTailscaleServePort,
526528
});
527529
refreshDesktopNetworkAccessState();
528-
setPendingTailscaleServeEndpoint(null);
530+
setPendingTailscaleServeSetup(null);
529531
});
530532
if (settled._tag === "Failure") {
531533
const error = Cause.squash(settled.cause);
@@ -543,11 +545,11 @@ function ConnectionsSettingsContent({
543545
setIsUpdatingTailscaleServe(false);
544546
};
545547

546-
const handleStartTailscaleServeSetup = (endpoint: AdvertisedEndpoint) => {
548+
const handleStartTailscaleServeSetup = (endpoint: AdvertisedEndpoint | null) => {
547549
setTailscaleServePortInput(
548550
String(desktopServerExposureState?.tailscaleServePort ?? DEFAULT_TAILSCALE_SERVE_PORT),
549551
);
550-
setPendingTailscaleServeEndpoint(endpoint);
552+
setPendingTailscaleServeSetup({ endpoint });
551553
};
552554

553555
const handleConfirmTailscaleServeDisable = async () => {
@@ -1097,35 +1099,27 @@ function ConnectionsSettingsContent({
10971099
);
10981100
};
10991101

1100-
const renderTailscaleRow = () => (
1101-
<SettingsRow
1102-
title={searchableSetting("tailscale-https").title}
1103-
description={
1104-
tailscaleHttpsEndpoint
1105-
? tailscaleHttpsEndpoint.status === "available"
1106-
? tailscaleHttpsEndpoint.httpBaseUrl
1107-
: "Use Tailscale Serve to expose this backend through a MagicDNS HTTPS URL."
1108-
: missingTailscaleEndpointDescription(desktopServerExposureState)
1109-
}
1110-
control={
1111-
tailscaleHttpsEndpoint ? (
1102+
const renderTailscaleRow = () => {
1103+
const row = tailscaleHttpsRow(desktopServerExposureState, tailscaleHttpsEndpoint);
1104+
return (
1105+
<SettingsRow
1106+
title={searchableSetting("tailscale-https").title}
1107+
description={row.description}
1108+
control={
11121109
<Switch
1113-
checked={tailscaleHttpsEndpoint.status === "available"}
1110+
checked={row.checked}
11141111
disabled={isUpdatingTailscaleServe}
11151112
onCheckedChange={(checked) => {
1116-
if (checked) {
1117-
handleStartTailscaleServeSetup(tailscaleHttpsEndpoint);
1118-
return;
1119-
}
1120-
handleStartTailscaleServeDisable(tailscaleHttpsEndpoint);
1113+
if (checked) handleStartTailscaleServeSetup(tailscaleHttpsEndpoint);
1114+
else setDisableTailscaleServeDialogOpen(true);
11211115
}}
11221116
aria-label="Enable Tailscale HTTPS"
11231117
/>
1124-
) : null
1125-
}
1126-
managed={tailscaleHttpsEndpoint?.status === "available" ? undefined : remoteClientsDenial}
1127-
/>
1128-
);
1118+
}
1119+
managed={row.checked ? undefined : remoteClientsDenial}
1120+
/>
1121+
);
1122+
};
11291123
const newestPairingLink = visibleDesktopPairingLinks.find(
11301124
(pairingLink) => pairingLink.id === newestPairingLinkId,
11311125
);
@@ -1624,10 +1618,10 @@ function ConnectionsSettingsContent({
16241618
</AlertDialogPopup>
16251619
</AlertDialog>
16261620
<Dialog
1627-
open={pendingTailscaleServeEndpoint !== null}
1621+
open={pendingTailscaleServeSetup !== null}
16281622
onOpenChange={(open) => {
16291623
if (isUpdatingTailscaleServe) return;
1630-
if (!open) setPendingTailscaleServeEndpoint(null);
1624+
if (!open) setPendingTailscaleServeSetup(null);
16311625
}}
16321626
>
16331627
<DialogPopup className="max-w-md">

0 commit comments

Comments
 (0)