diff --git a/.github/workflows/fork-principals.yml b/.github/workflows/fork-principals.yml index 1f1dd255d721f..c1f7ecf050a36 100644 --- a/.github/workflows/fork-principals.yml +++ b/.github/workflows/fork-principals.yml @@ -5,7 +5,7 @@ name: Fork principals on: pull_request: - branches: [main] + branches: [main, "feat/**"] workflow_dispatch: permissions: @@ -38,10 +38,16 @@ jobs: run: node apps/web/node_modules/playwright/cli.js install --with-deps --only-shell chromium - name: Typecheck - run: vp run --filter @t3tools/contracts --filter t3 typecheck + run: vp run --filter @t3tools/contracts --filter @t3tools/client-runtime --filter @t3tools/web --filter t3 typecheck - name: Test contracts run: vp run --filter @t3tools/contracts test - name: Test server run: vp run --filter t3 test + + - name: Test session-sharing web and client-runtime code + if: ${{ !cancelled() }} + run: | + (cd packages/client-runtime && vp test run src/state/sessionAccess.test.ts) + (cd apps/web && vp test run src/sidebarProjectGrouping.test.ts src/components/chat/ShareThreadDialog.browser.test.tsx) diff --git a/apps/server/src/auth/EnvironmentAuth.ts b/apps/server/src/auth/EnvironmentAuth.ts index 4124b36576273..5e36bec083321 100644 --- a/apps/server/src/auth/EnvironmentAuth.ts +++ b/apps/server/src/auth/EnvironmentAuth.ts @@ -854,6 +854,9 @@ export const make = Effect.gen(function* () { ...authScopeResponse(session.scopes), sessionMethod: session.method, ...(session.expiresAt ? { expiresAt: DateTime.toUtc(session.expiresAt) } : {}), + ...(principalOfSubject(session.subject) !== DEFAULT_PRINCIPAL_ID + ? { principal: principalOfSubject(session.subject) } + : {}), }) satisfies AuthSessionState, ), Effect.catchIf(isServerAuthCredentialError, () => diff --git a/apps/server/src/auth/RpcAuthorization.ts b/apps/server/src/auth/RpcAuthorization.ts index 8f692534d140f..b5e39f72577e7 100644 --- a/apps/server/src/auth/RpcAuthorization.ts +++ b/apps/server/src/auth/RpcAuthorization.ts @@ -61,6 +61,8 @@ export const RPC_REQUIRED_SCOPES = { [ORCHESTRATION_V2_WS_METHODS.subscribeThread]: AuthOrchestrationReadScope, [ORCHESTRATION_V2_WS_METHODS.subscribeCommandOutput]: AuthOrchestrationReadScope, [WS_METHODS.projectsMutate]: AuthOrchestrationOperateScope, + [WS_METHODS.sessionAccessList]: AuthOrchestrationReadScope, + [WS_METHODS.sessionAccessThreadShares]: AuthOrchestrationReadScope, [WS_METHODS.serverProbe]: AuthOrchestrationReadScope, [WS_METHODS.serverGetConfig]: AuthOrchestrationReadScope, [WS_METHODS.serverGetNpmRelease]: AuthOrchestrationReadScope, diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 6fd54db6bd52a..485f9052e05e0 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -227,6 +227,7 @@ import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../termina import { useKnownTerminalSessions, useThreadRunningTerminalIds } from "../state/terminalSessions"; import { useEnvironmentQuery } from "../state/query"; import { useEnvironmentScope } from "~/state/session"; +import { useThreadAccessRole } from "~/state/sessionAccess"; import { primaryServerAvailableEditorsAtom, primaryServerKeybindingsAtom, @@ -423,7 +424,11 @@ export default function ChatView(props: ChatViewProps) { embedded: parentPanel, } = props; const embedded = parentPanel !== undefined; - const canOperateThread = useEnvironmentScope(environmentId, AuthOrchestrationOperateScope); + const hasOperateScope = useEnvironmentScope(environmentId, AuthOrchestrationOperateScope); + const isSessionViewer = + useThreadAccessRole(routeKind === "server" ? scopeThreadRef(environmentId, threadId) : null) === + "viewer"; + const canOperateThread = hasOperateScope && !isSessionViewer; const canOperateTerminal = useEnvironmentScope(environmentId, AuthTerminalOperateScope); const draftId = routeKind === "draft" ? props.draftId : null; const handleNewThread = useNewThreadHandler(); diff --git a/apps/web/src/components/CommandPalette.tsx b/apps/web/src/components/CommandPalette.tsx index 068808707b4f5..c6b11e7a88e18 100644 --- a/apps/web/src/components/CommandPalette.tsx +++ b/apps/web/src/components/CommandPalette.tsx @@ -243,6 +243,8 @@ import { ProjectFilePicker } from "./files/ProjectFilePicker"; import { openLinkPullRequestDialog } from "./pullRequest/LinkPullRequestDialog"; import { canShareWithGuestAtom } from "./chat/guestShareAvailability"; import { openGuestShareDialog } from "./chat/guestShareDialogState"; +import { openShareThreadDialog } from "./chat/shareThreadDialogState"; +import { readCanShareThread } from "../state/sessionAccess"; import { ProjectContentSearchDialog } from "./search/ProjectContentSearchDialog"; import { settingsForThisPlatform, SETTINGS_SECTION_LABELS } from "./settings/settingsSearch"; import { primaryServerKeybindingsAtom } from "../state/server"; @@ -1412,6 +1414,22 @@ function OpenCommandPaletteDialog(props: { }); } + if (activeThread !== null) { + const threadRef = scopeThreadRef(activeThread.environmentId, activeThread.id); + if (readCanShareThread(threadRef, activeThread.source.ownerPrincipal)) { + actionItems.push({ + kind: "action", + value: "action:share-thread-with-principal", + searchTerms: ["share", "invite", "viewer", "participant", "session", "group"], + title: "Share…", + icon: , + run: async () => { + openShareThreadDialog(threadRef); + }, + }); + } + } + if (activeThread !== null) { const thread = activeThread; actionItems.push({ diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index deede26763fdd..df91d68da49bc 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -112,6 +112,7 @@ import { projectGroupsSpanEnvironments, resolveSidebarProjectScopeKeys, getSidebarProjectSettingsKey, + partitionSharedThreads, type SidebarProjectSnapshot, } from "../sidebarProjectGrouping"; import { resolveProjectExpanded, useUiStateStore } from "../uiStateStore"; @@ -128,6 +129,8 @@ import { useHandleNewThread } from "../hooks/useHandleNewThread"; import { useOrderWhileOpen } from "../hooks/useOrderWhileOpen"; import { useProjectPin } from "../hooks/useProjectGroupUpdate"; import { useSidebarProjectGroups } from "../hooks/useSidebarProjectGroups"; +import { readCanShareThread, useSharedSidebarInput } from "../state/sessionAccess"; +import { SidebarSharedThreads } from "./sidebar/SidebarSharedThreads"; import { useTerminalFocus } from "../hooks/useTerminalFocus"; import { isCommandPaletteOpen, openCommandPalette } from "../commandPaletteBus"; import { registerSettleAndAdvance } from "../settleAndAdvance"; @@ -162,6 +165,7 @@ import { readEnvironmentScope, useEnvironmentScope } from "../state/session"; import { appAtomRegistry } from "../rpc/atomRegistry"; import { canShareWithGuestAtom } from "./chat/guestShareAvailability"; import { openGuestShareDialog } from "./chat/guestShareDialogState"; +import { openShareThreadDialog } from "./chat/shareThreadDialogState"; import { buildThreadRouteParams, resolveActiveThreadRouteRef, @@ -1116,7 +1120,11 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve ), ), ); - const threads = useQuietThreadShells(); + const allThreads = useQuietThreadShells(); + const { mine: threads, shared: sharedThreadSections } = partitionSharedThreads({ + threads: allThreads, + ...useSharedSidebarInput(useEnvironmentIdentities().map(({ environmentId }) => environmentId)), + }); const routeRowThreadKey = routeThreadRef === null ? null @@ -2644,6 +2652,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve canShareWithGuest: appAtomRegistry.get( canShareWithGuestAtom(threadRef.environmentId), ), + canShareSession: readCanShareThread(threadRef, thread.source.ownerPrincipal), canTurnIntoProject: canTurnThreadIntoProject(threadRef), supports: { settlement: configLoaded, @@ -2766,6 +2775,9 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve case "rename": startThreadRename(threadRef, thread.title); return; + case "share-session": + openShareThreadDialog(threadRef); + return; case "share-guest": openGuestShareDialog(threadRef); return; @@ -3638,6 +3650,13 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve )} ) : null} + {!isSearchingThreads ? ( + + ) : null} diff --git a/apps/web/src/components/auth/PairingRouteSurface.tsx b/apps/web/src/components/auth/PairingRouteSurface.tsx index 8bedc8b2e7117..c73ce5605ef50 100644 --- a/apps/web/src/components/auth/PairingRouteSurface.tsx +++ b/apps/web/src/components/auth/PairingRouteSurface.tsx @@ -6,10 +6,13 @@ import React, { startTransition, useEffect, useEffectEvent, useRef, useState } f import { connectPairing } from "../../connection/onboarding"; import { peekPairingTokenFromUrl, + resolvePrimaryEnvironmentHttpUrl, stripPairingTokenFromUrl, submitServerAuthCredential, } from "../../environments/primary"; +import { isElectron } from "../../env"; import { readHostedPairingRequest } from "../../hostedPairing"; +import { ensureLocalApi } from "../../localApi"; import { Button } from "../ui/button"; import { Input } from "../ui/input"; import { StandalonePage, StandalonePageHeader } from "../ui/standalone-page"; @@ -62,6 +65,19 @@ export function PairingRouteSurface({ }); }; + const signInWithOidc = async () => { + const url = resolvePrimaryEnvironmentHttpUrl("/auth/oidc/start", { + client: isElectron ? "desktop" : "web", + }); + if (!isElectron) { + window.location.assign(url); + return; + } + await ensureLocalApi() + .shell.openExternal(url) + .catch((error) => setErrorMessage(errorMessageFromUnknown(error))); + }; + const handleSubmit = async (event?: React.SubmitEvent) => { event?.preventDefault(); await submitCredential(credential); @@ -89,6 +105,19 @@ export function PairingRouteSurface({ description={describeAuthGate(auth.bootstrapMethods)} /> + {auth.oidcSignIn ? ( +
+ +

+ {isElectron + ? "Opens your browser; the app signs in when you return." + : "Or pair this device with a token below."} +

+
+ ) : null} +
void handleSubmit(event)}>