From b842bc0e5e33c4e7d595ea0f86a0fd170f78d2b2 Mon Sep 17 00:00:00 2001 From: "Can H. Tartanoglu" Date: Mon, 2 Nov 2026 10:34:54 +0000 Subject: [PATCH 1/4] feat(web): sign in with Kanidm, share sessions and group them by person MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-in people need to see their own work first and bring each other in. With OIDC configured, the pairing screen offers "Sign in with Kanidm" (browser redirect, or the system browser plus t3code://pair on desktop). The sidebar keeps your own threads in the existing project view and adds "Shared with me", grouped by owner and session group. Share… in the thread menu and command palette invites a principal as viewer or participant and files the thread in a session group; Settings shows who you are and manages groups. Messages from someone else carry their name, and viewers get a disabled composer. With the default owner principal nothing changes. --- apps/server/src/auth/EnvironmentAuth.ts | 3 + apps/server/src/auth/RpcAuthorization.ts | 2 + apps/web/src/components/ChatView.tsx | 7 +- apps/web/src/components/CommandPalette.tsx | 18 ++ apps/web/src/components/Sidebar.tsx | 21 ++- .../components/auth/PairingRouteSurface.tsx | 29 +++ apps/web/src/components/chat/ChatComposer.tsx | 2 + .../chat/ComposerSessionViewerBanner.tsx | 27 +++ .../chat/ShareThreadDialog.browser.test.tsx | 53 ++++++ .../src/components/chat/ShareThreadDialog.tsx | 172 ++++++++++++++++++ .../chat/TimelineUserMessageRow.tsx | 9 + .../components/chat/shareThreadDialogState.ts | 14 ++ .../sessionAccess/PrincipalRoleForm.tsx | 78 ++++++++ .../settings/SessionAccessSettings.tsx | 143 +++++++++++++++ .../components/settings/SettingsPanels.tsx | 2 + .../sidebar/SidebarSharedThreads.tsx | 62 +++++++ .../src/components/threadActionMenu.logic.ts | 6 + apps/web/src/hooks/useThreadActionMenu.ts | 6 + apps/web/src/routes/__root.tsx | 3 + apps/web/src/session-logic.ts | 3 + apps/web/src/sidebarProjectGrouping.test.ts | 52 ++++++ apps/web/src/sidebarProjectGrouping.ts | 58 +++++- apps/web/src/state/sessionAccess.ts | 112 ++++++++++++ apps/web/src/types.ts | 1 + packages/client-runtime/package.json | 4 + .../src/state/sessionAccess.test.ts | 49 +++++ .../client-runtime/src/state/sessionAccess.ts | 73 ++++++++ packages/contracts/src/auth.ts | 2 + .../contracts/src/clientRpcPermissions.ts | 2 - 29 files changed, 1008 insertions(+), 5 deletions(-) create mode 100644 apps/web/src/components/chat/ComposerSessionViewerBanner.tsx create mode 100644 apps/web/src/components/chat/ShareThreadDialog.browser.test.tsx create mode 100644 apps/web/src/components/chat/ShareThreadDialog.tsx create mode 100644 apps/web/src/components/chat/shareThreadDialogState.ts create mode 100644 apps/web/src/components/sessionAccess/PrincipalRoleForm.tsx create mode 100644 apps/web/src/components/settings/SessionAccessSettings.tsx create mode 100644 apps/web/src/components/sidebar/SidebarSharedThreads.tsx create mode 100644 apps/web/src/sidebarProjectGrouping.test.ts create mode 100644 apps/web/src/state/sessionAccess.ts create mode 100644 packages/client-runtime/src/state/sessionAccess.test.ts create mode 100644 packages/client-runtime/src/state/sessionAccess.ts diff --git a/apps/server/src/auth/EnvironmentAuth.ts b/apps/server/src/auth/EnvironmentAuth.ts index 4124b3657627..5e36bec08332 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 8f692534d140..b5e39f72577e 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 6fd54db6bd52..485f9052e05e 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 068808707b4f..c6b11e7a88e1 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 deede26763fd..df91d68da49b 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 8bedc8b2e711..c73ce5605ef5 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)}>