diff --git a/apps/desktop/src/backend/DesktopServerExposure.test.ts b/apps/desktop/src/backend/DesktopServerExposure.test.ts index c222237dffa7..ddebbf7fb6fb 100644 --- a/apps/desktop/src/backend/DesktopServerExposure.test.ts +++ b/apps/desktop/src/backend/DesktopServerExposure.test.ts @@ -181,6 +181,27 @@ describe("DesktopServerExposure", () => { ); }); + it.effect("reads Tailscale by default, and never after Serve is turned off locally", () => { + let statusReads = 0; + return withHarness( + lanNetworkInterfaces, + Effect.gen(function* () { + const serverExposure = yield* DesktopServerExposure.DesktopServerExposure; + yield* serverExposure.configureFromSettings({ port: 4173 }); + yield* serverExposure.getAdvertisedEndpoints; + assert.equal(statusReads, 1); + + yield* serverExposure.setTailscaleServeEnabled({ enabled: false }); + yield* serverExposure.getAdvertisedEndpoints; + assert.equal(statusReads, 1); + }), + {}, + layerMockSpawner("{}", () => { + statusReads += 1; + }), + ); + }); + it.effect("falls back to local-only without losing the requested network preference", () => withHarness( emptyNetworkInterfaces, @@ -253,7 +274,7 @@ describe("DesktopServerExposure", () => { mode: "network-accessible", endpointUrl: "http://192.168.1.20:4173", advertisedHost: "192.168.1.20", - tailscaleServeEnabled: false, + tailscaleServeEnabled: true, tailscaleServePort: 443, }); diff --git a/apps/desktop/src/settings/DesktopAppSettings.test.ts b/apps/desktop/src/settings/DesktopAppSettings.test.ts index 04406f63c6b3..bb07e2cc998e 100644 --- a/apps/desktop/src/settings/DesktopAppSettings.test.ts +++ b/apps/desktop/src/settings/DesktopAppSettings.test.ts @@ -4,6 +4,7 @@ import { assert, describe, it } from "@effect/vitest"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; +import * as Option from "effect/Option"; import * as PlatformError from "effect/PlatformError"; import * as Schema from "effect/Schema"; import * as Tracer from "effect/Tracer"; @@ -295,6 +296,7 @@ describe("DesktopSettings", () => { yield* settings.setMainWindowBounds({ x: -1200, y: 40, width: 400, height: 360 }, true); yield* settings.setServerExposureMode("network-accessible"); + yield* settings.setTailscaleServe({ enabled: false, port: Option.none() }); const persisted = yield* decodeDesktopSettingsPatch( yield* fileSystem.readFileString(environment.desktopSettingsPath), @@ -303,6 +305,7 @@ describe("DesktopSettings", () => { mainWindowBounds: { x: -1200, y: 40, width: 400, height: 360 }, mainWindowMaximized: true, serverExposureMode: "network-accessible", + tailscaleServeEnabled: false, } satisfies typeof DesktopSettingsPatch.Type); const restored = yield* Effect.gen(function* () { @@ -311,6 +314,7 @@ describe("DesktopSettings", () => { }).pipe(Effect.provide(DesktopAppSettings.layer)); assert.deepEqual(restored.mainWindowBounds, persisted.mainWindowBounds); assert.isTrue(restored.mainWindowMaximized); + assert.isFalse(restored.tailscaleServeEnabled); }), ), ); @@ -381,7 +385,8 @@ describe("DesktopSettings", () => { mainWindowBounds: null, mainWindowMaximized: false, serverExposureMode: "local-only", - tailscaleServeEnabled: false, + // A missing key reads as on; an off saved before it became the default left no key. + tailscaleServeEnabled: true, tailscaleServePort: 443, updateChannel: "nightly", updateChannelConfiguredByUser: false, @@ -410,7 +415,8 @@ describe("DesktopSettings", () => { mainWindowBounds: null, mainWindowMaximized: false, serverExposureMode: "local-only", - tailscaleServeEnabled: false, + // A missing key reads as on; an off saved before it became the default left no key. + tailscaleServeEnabled: true, tailscaleServePort: 443, updateChannel: "latest", updateChannelConfiguredByUser: true, diff --git a/apps/desktop/src/settings/DesktopAppSettings.ts b/apps/desktop/src/settings/DesktopAppSettings.ts index e81da7066064..302f1472a187 100644 --- a/apps/desktop/src/settings/DesktopAppSettings.ts +++ b/apps/desktop/src/settings/DesktopAppSettings.ts @@ -74,7 +74,8 @@ export const DEFAULT_DESKTOP_SETTINGS: DesktopSettings = { mainWindowBounds: null, mainWindowMaximized: false, serverExposureMode: "local-only", - tailscaleServeEnabled: false, + // Closura fleet default. Only an explicit off is stored; Serve stays inert without Tailscale. + tailscaleServeEnabled: true, tailscaleServePort: DEFAULT_TAILSCALE_SERVE_PORT, updateChannel: "latest", updateChannelConfiguredByUser: false, @@ -231,7 +232,7 @@ function normalizeDesktopSettingsDocument( mainWindowMaximized: mainWindowBounds !== null && parsed.mainWindowMaximized === true, serverExposureMode: parsed.serverExposureMode === "network-accessible" ? "network-accessible" : "local-only", - tailscaleServeEnabled: parsed.tailscaleServeEnabled === true, + tailscaleServeEnabled: parsed.tailscaleServeEnabled ?? defaultSettings.tailscaleServeEnabled, tailscaleServePort: normalizeTailscaleServePort(parsed.tailscaleServePort), updateChannel: updateChannelConfiguredByUser ? Option.getOrElse(parsedUpdateChannel, () => defaultSettings.updateChannel) diff --git a/apps/web/src/components/Sidebar.drag.browser.test.tsx b/apps/web/src/components/Sidebar.drag.browser.test.tsx index f3402f20a4bc..58b4b4548cf1 100644 --- a/apps/web/src/components/Sidebar.drag.browser.test.tsx +++ b/apps/web/src/components/Sidebar.drag.browser.test.tsx @@ -120,6 +120,8 @@ it("keeps focus in the search box when a click picks a search result", async () projectDisplayName={null} environmentLabel={null} environmentMachine="server" + senderLabel={null} + senderByAgent={false} providerEntryByInstanceId={new Map()} isHighlighted={false} isRouteActive={false} diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 3461a2ae8c7c..81aca58f2852 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -1,9 +1,11 @@ import { SidebarThreadFilterMenu } from "./sidebar/SidebarThreadFilterMenu"; import { matchesThreadListFilter, threadListFilterOf } from "./sidebar/threadListFilter.logic"; import { + launchingThreadIdOf, resolveMachineOwners, resolveThreadAttributions, threadAttributionKey, + threadSenderLine, } from "@t3tools/client-runtime/state/thread-attribution"; import { matchesOlderSettledGroup, @@ -1138,6 +1140,19 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const threadAttributions = resolveThreadAttributions(threads, machineOwners); const attributionOf = (thread: Pick) => threadAttributions.get(threadAttributionKey(thread)) ?? "unknown"; + // Ids are unique across machines, and an agent often launches work on another one. + const threadTitleById = new Map( + threads.map((thread) => [thread.id, thread.title]), + ); + const senderLineOf = (thread: EnvironmentThreadShell) => { + const attribution = threadAttributions.get(threadAttributionKey(thread)); + if (attribution === undefined) return null; + const launcherId = launchingThreadIdOf(thread); + return threadSenderLine( + attribution, + launcherId === null ? null : (threadTitleById.get(launcherId) ?? null), + ); + }; // Search always looks across every inbox, sender and environment. const listFilterApplies = threadSearchQuery.trim().length === 0; const inboxThreads = listFilterApplies @@ -3304,6 +3319,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const threadKey = scopedThreadKey( scopeThreadRef(thread.environmentId, thread.id), ); + const senderLine = senderLineOf(thread); return ( { }); }); +describe("tailscaleHttpsRow", () => { + const url = "https://laptop.tail.ts.net"; + const on = { tailscaleServeEnabled: true } as const; + const off = { tailscaleServeEnabled: false } as const; + + it("follows the saved setting, not whether Serve answers", () => { + expect( + [ + tailscaleHttpsRow(on, { status: "available", httpBaseUrl: url }), + tailscaleHttpsRow(on, { status: "unavailable", httpBaseUrl: url }), + tailscaleHttpsRow(on, null), + tailscaleHttpsRow(off, { status: "available", httpBaseUrl: url }), + tailscaleHttpsRow(off, null), + ].map((row) => row.checked), + ).toEqual([true, true, true, false, false]); + }); +}); + const baseWslState: DesktopWslState = { enabled: false, distro: null, diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.ts index f78ef2934719..3cef6e51083c 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.logic.ts +++ b/apps/web/src/components/settings/ConnectionsSettings.logic.ts @@ -61,14 +61,31 @@ export function isQrShareableEndpoint(endpoint: AdvertisedEndpoint): boolean { return endpoint.status !== "unavailable" && endpoint.reachability !== "loopback"; } -/** Desktop skips Tailscale probing until network/Serve is enabled to avoid macOS prompts; absence then - * means unchecked. */ -export function missingTailscaleEndpointDescription( - state: Pick | null, -): string { - return state && state.mode !== "network-accessible" && !state.tailscaleServeEnabled - ? "Turn on Network access to detect Tailscale." - : "Start Tailscale to set up HTTPS access through MagicDNS."; +/** + * The Tailscale HTTPS switch and its status line. Serve is on by default and does nothing until + * Tailscale runs here, signed in with MagicDNS. Desktop skips Tailscale probing while Serve and + * network access are off to avoid macOS prompts, so no endpoint then says nothing about Tailscale. + */ +export function tailscaleHttpsRow( + state: Pick | null, + endpoint: Pick | null, +): { readonly checked: boolean; readonly description: string } { + if (!state?.tailscaleServeEnabled) { + return { + checked: false, + description: endpoint + ? `Off. Turn on to serve this backend at ${endpoint.httpBaseUrl}` + : "Off. Turn on to serve this backend over Tailscale HTTPS.", + }; + } + return { + checked: true, + description: !endpoint + ? "On. Inactive until Tailscale runs here, signed in with MagicDNS." + : endpoint.status === "available" + ? `On at ${endpoint.httpBaseUrl}` + : `On, but ${endpoint.httpBaseUrl} doesn't answer. Tailscale Serve needs HTTPS certificates on the tailnet and its port free.`, + }; } export function resolveTailscaleServeBaseUrl( diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx index bb99f1bc1e83..42fc24e013c3 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.tsx +++ b/apps/web/src/components/settings/ConnectionsSettings.tsx @@ -31,7 +31,7 @@ import { applyWslEnableSelection, connectDeviceName, isWslSettingsRowVisible, - missingTailscaleEndpointDescription, + tailscaleHttpsRow, resolveLocalVersionStatusLabel, resolveTailscaleServeBaseUrl, } from "./ConnectionsSettings.logic"; @@ -370,8 +370,10 @@ function ConnectionsSettingsContent({ | { readonly kind: "wsl-only"; readonly nextValue: boolean }; const [pendingWslChange, setPendingWslChange] = useState(null); const isWslConfirmDialogOpen = pendingWslChange !== null; - const [pendingTailscaleServeEndpoint, setPendingTailscaleServeEndpoint] = - useState(null); + // Setup can start before Tailscale reports a MagicDNS name, so the endpoint may be null. + const [pendingTailscaleServeSetup, setPendingTailscaleServeSetup] = useState<{ + readonly endpoint: AdvertisedEndpoint | null; + } | null>(null); const [disableTailscaleServeDialogOpen, setDisableTailscaleServeDialogOpen] = useState(false); const [tailscaleServePortInput, setTailscaleServePortInput] = useState( String(DEFAULT_TAILSCALE_SERVE_PORT), @@ -469,7 +471,7 @@ function ConnectionsSettingsContent({ parsedTailscaleServePort <= 65_535; const pendingTailscaleServeBaseUrl = resolveTailscaleServeBaseUrl( - pendingTailscaleServeEndpoint, + pendingTailscaleServeSetup?.endpoint ?? null, parsedTailscaleServePort, isTailscaleServePortValid, ); @@ -525,7 +527,7 @@ function ConnectionsSettingsContent({ port: parsedTailscaleServePort, }); refreshDesktopNetworkAccessState(); - setPendingTailscaleServeEndpoint(null); + setPendingTailscaleServeSetup(null); }); if (settled._tag === "Failure") { const error = Cause.squash(settled.cause); @@ -543,11 +545,11 @@ function ConnectionsSettingsContent({ setIsUpdatingTailscaleServe(false); }; - const handleStartTailscaleServeSetup = (endpoint: AdvertisedEndpoint) => { + const handleStartTailscaleServeSetup = (endpoint: AdvertisedEndpoint | null) => { setTailscaleServePortInput( String(desktopServerExposureState?.tailscaleServePort ?? DEFAULT_TAILSCALE_SERVE_PORT), ); - setPendingTailscaleServeEndpoint(endpoint); + setPendingTailscaleServeSetup({ endpoint }); }; const handleConfirmTailscaleServeDisable = async () => { @@ -1097,35 +1099,27 @@ function ConnectionsSettingsContent({ ); }; - const renderTailscaleRow = () => ( - { + const row = tailscaleHttpsRow(desktopServerExposureState, tailscaleHttpsEndpoint); + return ( + { - if (checked) { - handleStartTailscaleServeSetup(tailscaleHttpsEndpoint); - return; - } - handleStartTailscaleServeDisable(tailscaleHttpsEndpoint); + if (checked) handleStartTailscaleServeSetup(tailscaleHttpsEndpoint); + else setDisableTailscaleServeDialogOpen(true); }} aria-label="Enable Tailscale HTTPS" /> - ) : null - } - managed={tailscaleHttpsEndpoint?.status === "available" ? undefined : remoteClientsDenial} - /> - ); + } + managed={row.checked ? undefined : remoteClientsDenial} + /> + ); + }; const newestPairingLink = visibleDesktopPairingLinks.find( (pairingLink) => pairingLink.id === newestPairingLinkId, ); @@ -1624,10 +1618,10 @@ function ConnectionsSettingsContent({ { if (isUpdatingTailscaleServe) return; - if (!open) setPendingTailscaleServeEndpoint(null); + if (!open) setPendingTailscaleServeSetup(null); }} > diff --git a/apps/web/src/components/sidebar/SidebarThreadRow.tsx b/apps/web/src/components/sidebar/SidebarThreadRow.tsx index d9e17f4df974..991db4b02bb7 100644 --- a/apps/web/src/components/sidebar/SidebarThreadRow.tsx +++ b/apps/web/src/components/sidebar/SidebarThreadRow.tsx @@ -243,6 +243,8 @@ function SidebarThreadTooltip({ projectDisplayName, environmentLabel, environmentMachine, + senderLabel, + senderByAgent, providerEntry, providerEntryByInstanceId, showInstanceBadge, @@ -257,6 +259,8 @@ function SidebarThreadTooltip({ projectDisplayName: string | null; environmentLabel: string | null; environmentMachine: EnvironmentMachineKind; + senderLabel: string | null; + senderByAgent: boolean; providerEntry: SidebarProviderEntry | null; providerEntryByInstanceId: ReadonlyMap; showInstanceBadge: boolean; @@ -301,6 +305,16 @@ function SidebarThreadTooltip({
{environmentLabel}
) : null} + {senderLabel ? ( +
+ {senderByAgent ? ( + + ) : ( + + )} +
{senderLabel}
+
+ ) : null} {thread.branch ? (
@@ -602,6 +616,9 @@ type SidebarThreadRowProps = { jumpLabel: string | null; currentEnvironmentId: string | null; attribution: ThreadAttribution; + /** The hover card's sender line; null when this client hasn't resolved the thread. */ + senderLabel: string | null; + senderByAgent: boolean; environmentLabel: string | null; environmentMachine: EnvironmentMachineKind; scratchMachineLabel: string | null; @@ -873,6 +890,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP projectDisplayName={props.projectDisplayName} environmentLabel={props.environmentLabel} environmentMachine={props.environmentMachine} + senderLabel={props.senderLabel} + senderByAgent={props.senderByAgent} providerEntry={providerEntry} providerEntryByInstanceId={props.providerEntryByInstanceId} showInstanceBadge={showInstanceBadge} @@ -1684,6 +1703,8 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props projectDisplayName: string | null; environmentLabel: string | null; environmentMachine: EnvironmentMachineKind; + senderLabel: string | null; + senderByAgent: boolean; providerEntryByInstanceId: ReadonlyMap; isHighlighted: boolean; isRouteActive: boolean; @@ -1862,6 +1883,8 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props projectDisplayName={props.projectDisplayName} environmentLabel={props.environmentLabel} environmentMachine={props.environmentMachine} + senderLabel={props.senderLabel} + senderByAgent={props.senderByAgent} providerEntry={providerEntry} providerEntryByInstanceId={props.providerEntryByInstanceId} showInstanceBadge={showInstanceBadge} diff --git a/docs/user/remote-access.md b/docs/user/remote-access.md index 5c0d896731b4..6776b8a2a67b 100644 --- a/docs/user/remote-access.md +++ b/docs/user/remote-access.md @@ -195,8 +195,10 @@ Mobile keeps its manual environment selection. ### Tailscale HTTPS -Join both devices to the same tailnet. In the desktop app, enable **Tailscale -HTTPS** in **Settings → Sharing & access**. Turn it off there to remove that route. +Join both devices to the same tailnet. The desktop app turns on **Tailscale +HTTPS** by default, and **Settings → Sharing & access** shows its status. It does +nothing until Tailscale is installed and signed in. Turn it off there to remove +that route; the app keeps that choice. Your tailnet needs MagicDNS and HTTPS certificates enabled; see [Tailscale's HTTPS setup](https://tailscale.com/docs/how-to/set-up-https-certificates). diff --git a/packages/client-runtime/src/state/threadAttribution.test.ts b/packages/client-runtime/src/state/threadAttribution.test.ts index d4753ebeb90b..cc19d4c25256 100644 --- a/packages/client-runtime/src/state/threadAttribution.test.ts +++ b/packages/client-runtime/src/state/threadAttribution.test.ts @@ -1,7 +1,12 @@ import { EnvironmentId, makeThreadInbox, ThreadId, type ThreadInbox } from "@t3tools/contracts"; import { describe, expect, it } from "vite-plus/test"; -import { resolveThreadAttributions, type AttributableThread } from "./threadAttribution.ts"; +import { + launchingThreadIdOf, + resolveThreadAttributions, + threadSenderLine, + type AttributableThread, +} from "./threadAttribution.ts"; const asus = EnvironmentId.make("asus"); const air = EnvironmentId.make("air"); @@ -84,4 +89,30 @@ describe("thread attribution", () => { b: "unknown", }); }); + + it("names the launching thread for agent work, and says plainly when the sender is unknown", () => { + const launched = ( + inbox: ThreadInbox | null, + options: { parent?: string; createdBy?: string }, + ) => launchingThreadIdOf(thread("t", inbox, options)); + expect([ + launched(makeThreadInbox({ actor: bot }), { parent: "p" }), + launched(makeThreadInbox({ actor: { kind: "agent", id: "agent" } }), { parent: "p" }), + launched(null, { parent: "p", createdBy: "agent" }), + launched(makeThreadInbox({ actor: kameron }), { parent: "p" }), + ]).toEqual(["lead", "p", "p", null]); + expect([ + threadSenderLine("kameron", "Fleet rollout"), + threadSenderLine("jeff-agents", "Fleet rollout"), + threadSenderLine("jeff-agents", null), + threadSenderLine("unknown", "Fleet rollout"), + threadSenderLine("unknown", null), + ]).toEqual([ + { label: "Kameron", byAgent: false }, + { label: "Jeff's agents, from “Fleet rollout”", byAgent: true }, + { label: "Jeff's agents", byAgent: true }, + { label: "An agent, from “Fleet rollout”", byAgent: true }, + { label: "Sender unknown", byAgent: false }, + ]); + }); }); diff --git a/packages/client-runtime/src/state/threadAttribution.ts b/packages/client-runtime/src/state/threadAttribution.ts index 180d4874c3ff..08668b50c9fb 100644 --- a/packages/client-runtime/src/state/threadAttribution.ts +++ b/packages/client-runtime/src/state/threadAttribution.ts @@ -107,3 +107,27 @@ export function resolveThreadAttributions( } return resolved; } + +/** The thread an agent launched this one from: the agent origin's thread, else its parent. */ +export function launchingThreadIdOf(thread: AttributableThread): string | null { + const origin = thread.source.inbox?.origin; + // Launches without a calling thread record the bare id "agent". + if (origin?.kind === "agent" && origin.id !== "agent") return origin.id; + return origin?.kind === "agent" || thread.source.createdBy === "agent" + ? thread.lineage.parentThreadId + : null; +} + +/** The sentence form of an attribution, naming the launching thread for agent work. */ +export function threadSenderLine( + attribution: ThreadAttribution, + launcherTitle: string | null, +): { readonly label: string; readonly byAgent: boolean } { + const from = launcherTitle ? `, from “${launcherTitle}”` : ""; + if (attribution === "unknown") + return launcherTitle + ? { label: `An agent${from}`, byAgent: true } + : { label: "Sender unknown", byAgent: false }; + const byAgent = attribution.endsWith("-agents"); + return { label: `${THREAD_ATTRIBUTION_LABELS[attribution]}${byAgent ? from : ""}`, byAgent }; +}