GeezerVison is showing github.com — feat(server,web,mobile): an agent sets up a link to another environme… · pingdotgg/t3code@8b14660
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/LinkRequestCard.tsx +514Lines changed: 514 additions & 0 deletions Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/ThreadFeed.tsx +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,6 +18,7 @@ import { ThreadContextDivider } from "./thread-context-divider"; | 18 | 18 | import { ThreadHandoffDivider, ThreadHandoffRow } from "./thread-handoff-row"; | 19 | 19 | import { GuestBubbleTint, GuestMessageName } from "./guestMessageStyle"; | 20 | 20 | import { ThreadGuestPendingMessage, useThreadGuestShare } from "./ThreadGuestShareBar"; | | 21 | +import { LinkRequestCard } from "./LinkRequestCard"; | 21 | 22 | import { SecretRequestCard } from "./SecretRequestCard"; | 22 | 23 | import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator"; | 23 | 24 | import { | @@ -192,6 +193,7 @@ import { | 192 | 193 | threadFeedRunIsUnsettled, | 193 | 194 | isContextCompactionActivityGroup, | 194 | 195 | isContextHandoffActivityGroup, | | 196 | + isLinkRequestActivityGroup, | 195 | 197 | isSecretRequestActivityGroup, | 196 | 198 | type ThreadFeedEntry, | 197 | 199 | type ThreadFeedLatestRun, | @@ -1419,6 +1421,16 @@ function renderFeedEntry( | 1419 | 1421 | ); | 1420 | 1422 | } | 1421 | 1423 |
| | 1424 | + if (entry.type === "activity-group" && isLinkRequestActivityGroup(entry)) { | | 1425 | + return ( | | 1426 | + <LinkRequestCard | | 1427 | + environmentId={props.environmentId} | | 1428 | + projectedItem={entry.activities[0]!.projectedItem} | | 1429 | + iconColor={iconSubtleColor} | | 1430 | + /> | | 1431 | + ); | | 1432 | + } | | 1433 | + | 1422 | 1434 | if (entry.type === "activity-group" && isContextCompactionActivityGroup(entry)) { | 1423 | 1435 | const label = entry.activities[0]!.summary; | 1424 | 1436 | const item = entry.activities[0]!.projectedItem.item; | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/filePreview.test.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -271,6 +271,7 @@ vi.mock("../features/threads/thread-context-divider", () => ({})); | 271 | 271 | vi.mock("../features/threads/thread-handoff-row", () => ({})); | 272 | 272 | vi.mock("../features/threads/ThreadGuestShareBar", () => ({ useThreadGuestShare: () => null })); | 273 | 273 | vi.mock("../features/threads/SecretRequestCard", () => ({})); | | 274 | +vi.mock("../features/threads/LinkRequestCard", () => ({ LinkRequestCard: () => null })); | 274 | 275 | vi.mock("../features/threads/worktree-setup-card", () => ({})); | 275 | 276 | vi.mock("../features/threads/CopyTextButton", () => ({ CopyTextButton: () => null })); | 276 | 277 | vi.mock("../features/threads/thread-work-log", () => ({ THREAD_DISCLOSURE_TRANSITION_MS: 100 })); | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/threadActivity.ts +13-1Lines changed: 13 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -408,6 +408,12 @@ export function isSecretRequestActivityGroup(entry: ThreadFeedActivityGroup): bo | 408 | 408 | ); | 409 | 409 | } | 410 | 410 |
| | 411 | +export function isLinkRequestActivityGroup(entry: ThreadFeedActivityGroup): boolean { | | 412 | + return ( | | 413 | + entry.activities.length === 1 && entry.activities[0]?.projectedItem.item.type === "link_request" | | 414 | + ); | | 415 | +} | | 416 | + | 411 | 417 | function isUserInputActivityGroup(entry: ThreadFeedActivityGroup): boolean { | 412 | 418 | return entry.activities.some((activity) => activity.workEntry.questionAnswer !== undefined); | 413 | 419 | } | @@ -516,7 +522,8 @@ function itemIsProminent(item: OrchestrationV2TurnItem): boolean { | 516 | 522 | item.type === "thread_created" || | 517 | 523 | item.type === "system_notice" || | 518 | 524 | item.type === "proposed_plan" || | 519 | | - item.type === "secret_request" | | 525 | + item.type === "secret_request" || | | 526 | + item.type === "link_request" | 520 | 527 | ); | 521 | 528 | } | 522 | 529 |
| @@ -638,6 +645,8 @@ function itemIcon(item: OrchestrationV2TurnItem): ThreadFeedActivity["icon"] { | 638 | 645 | return "zap"; | 639 | 646 | case "secret_request": | 640 | 647 | return "lock"; | | 648 | + case "link_request": | | 649 | + return "globe"; | 641 | 650 | } | 642 | 651 | } | 643 | 652 |
| @@ -697,6 +706,8 @@ function itemSummary( | 697 | 706 | return "Thread created"; | 698 | 707 | case "secret_request": | 699 | 708 | return item.label; | | 709 | + case "link_request": | | 710 | + return `Link ${item.label ?? item.url ?? "an environment"}`; | 700 | 711 | case "dynamic_tool": { | 701 | 712 | const classified = classifyToolActivity({ | 702 | 713 | itemType: "dynamic_tool_call", | @@ -755,6 +766,7 @@ function itemPreview(item: OrchestrationV2TurnItem): string | null { | 755 | 766 | case "thread_created": | 756 | 767 | return item.targetThreadId; | 757 | 768 | case "secret_request": | | 769 | + case "link_request": | 758 | 770 | return item.reason || null; | 759 | 771 | case "subagent": | 760 | 772 | return item.result ?? item.progress ?? item.prompt; | |
Collapse file Copy file name to clipboard +43Lines changed: 43 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { useAtomValue } from "@effect/atom-react"; | | 2 | +import { linkableMachines } from "@t3tools/client-runtime/link-request"; | 1 | 3 | import { createPeerLinkEnvironmentAtoms } from "@t3tools/client-runtime/state/peerLinks"; | | 4 | +import type { EnvironmentId } from "@t3tools/contracts"; | | 5 | +import { useEffect, useEffectEvent, useMemo } from "react"; | 2 | 6 |
| 3 | 7 | import { connectionAtomRuntime } from "../connection/runtime"; | | 8 | +import { useEnvironments } from "./environments"; | | 9 | +import { relayEnvironmentDiscovery } from "./relay"; | | 10 | +import { useEnvironmentQuery } from "./query"; | | 11 | +import { useAtomCommand } from "./use-atom-command"; | 4 | 12 |
| 5 | 13 | export const peerLinkEnvironment = createPeerLinkEnvironmentAtoms(connectionAtomRuntime); | | 14 | + | | 15 | +/** | | 16 | + * The user's other machines, for picking one to link `environmentId` to, | | 17 | + * including those only on their T3 Connect account. Reads that environment's | | 18 | + * links only while `enabled`, since listing them asks every linked machine | | 19 | + * whether it answers. | | 20 | + */ | | 21 | +export function useLinkableMachines(environmentId: EnvironmentId, enabled: boolean) { | | 22 | + const { environments } = useEnvironments(); | | 23 | + const discovery = useAtomValue(relayEnvironmentDiscovery.stateValueAtom); | | 24 | + const refreshDiscovery = useAtomCommand(relayEnvironmentDiscovery.refresh, { | | 25 | + reportFailure: false, | | 26 | + }); | | 27 | + // Connect hosts are listed only once something asked for them, so ask on open. | | 28 | + const discoverIfUnasked = useEffectEvent(() => { | | 29 | + if (discovery.environments.size === 0 && !discovery.refreshing) void refreshDiscovery(); | | 30 | + }); | | 31 | + // oxlint-disable-next-line t3code/react-effect-budget -- discovery follows the picker's visibility, which a card's mount or a dialog's open sets | | 32 | + useEffect(() => { | | 33 | + if (enabled) discoverIfUnasked(); | | 34 | + }, [enabled]); | | 35 | + const links = useEnvironmentQuery( | | 36 | + enabled ? peerLinkEnvironment.list({ environmentId, input: {} }) : null, | | 37 | + ); | | 38 | + return useMemo( | | 39 | + () => | | 40 | + linkableMachines({ | | 41 | + environments, | | 42 | + threadEnvironmentId: environmentId, | | 43 | + links: links.data?.links ?? [], | | 44 | + connect: discovery.environments, | | 45 | + }), | | 46 | + [discovery.environments, environmentId, environments, links.data], | | 47 | + ); | | 48 | +} |
Collapse file Copy file name to clipboard +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { createPeerPairingCodeCommand } from "@t3tools/client-runtime/state/peerPairingCode"; | | 2 | +import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; | | 3 | +import type { AuthMcpClientAccess, EnvironmentId } from "@t3tools/contracts"; | | 4 | +import * as Result from "effect/Result"; | | 5 | + | | 6 | +import { connectionAtomRuntime } from "../connection/runtime"; | | 7 | +import { appAtomRegistry } from "./atom-registry"; | | 8 | + | | 9 | +const mintPairingCode = createPeerPairingCodeCommand(connectionAtomRuntime); | | 10 | + | | 11 | +/** | | 12 | + * A fresh pairing code minted on `environmentId` with this client's session | | 13 | + * there, for linking with `access`. Fails with `PeerPairingCodeError` when the | | 14 | + * session may not create one. | | 15 | + */ | | 16 | +export async function mintPairingCodeOn( | | 17 | + environmentId: EnvironmentId, | | 18 | + access: AuthMcpClientAccess, | | 19 | +): Promise<Result.Result<string, unknown>> { | | 20 | + const result = await mintPairingCode.run(appAtomRegistry, { environmentId, input: access }); | | 21 | + return result._tag === "Success" | | 22 | + ? Result.succeed(result.value) | | 23 | + : Result.fail(squashAtomCommandFailure(result)); | | 24 | +} |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/auth/EnvironmentAuth.ts +1-17Lines changed: 1 addition & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | AuthAccessTokenType, | 3 | 3 | AuthAccessWriteScope, | 4 | 4 | AuthOrchestrationOperateScope, | 5 | | - AuthOrchestrationReadScope, | 6 | | - AuthSettingsWriteScope, | 7 | | - AuthSourceControlWriteScope, | 8 | 5 | AuthStandardClientScopes, | 9 | 6 | type AuthAccessTokenResult, | 10 | 7 | type AuthBrowserSessionResult, | @@ -24,6 +21,7 @@ import { | 24 | 21 | type AuthWebSocketTicketUse, | 25 | 22 | DpopFailureReason, | 26 | 23 | type DpopFailureReason as DpopFailureReasonType, | | 24 | + mcpClientScopes, | 27 | 25 | } from "@t3tools/contracts"; | 28 | 26 | import { encodeOAuthScope } from "@t3tools/shared/oauthScope"; | 29 | 27 | import * as Context from "effect/Context"; | @@ -74,20 +72,6 @@ export interface IssuedBearerSession { | 74 | 72 | const MCP_CLIENT_SUBJECT = "mcp-client"; | 75 | 73 | const MCP_CLIENT_SESSION_TTL = Duration.days(30); | 76 | 74 |
| 77 | | -export const mcpClientScopes = ( | 78 | | - access: AuthMcpClientAccess, | 79 | | -): ReadonlyArray<AuthEnvironmentScope> => | 80 | | - access === "read-only" | 81 | | - ? [AuthOrchestrationReadScope] | 82 | | - : access === "full-access" | 83 | | - ? [ | 84 | | - AuthOrchestrationReadScope, | 85 | | - AuthOrchestrationOperateScope, | 86 | | - AuthSettingsWriteScope, | 87 | | - AuthSourceControlWriteScope, | 88 | | - ] | 89 | | - : [AuthOrchestrationReadScope, AuthOrchestrationOperateScope]; | 90 | | - | 91 | 75 | export interface McpClientSession { | 92 | 76 | readonly sessionId: AuthSessionId; | 93 | 77 | readonly label: string; | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/auth/McpOAuth.test.ts +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import * as NodeServices from "@effect/platform-node/NodeServices"; | 2 | 2 | import { | | 3 | + AuthMcpClientAccess, | 3 | 4 | AuthStandardClientScopes, | 4 | 5 | type AuthCreatePairingCredentialInput, | 5 | 6 | EnvironmentHttpApi, | | 7 | + mcpClientScopes, | 6 | 8 | } from "@t3tools/contracts"; | 7 | 9 | import { expect, it } from "@effect/vitest"; | 8 | 10 | import * as Context from "effect/Context"; | @@ -480,6 +482,23 @@ it.live( | 480 | 482 | ), | 481 | 483 | ); | 482 | 484 |
| | 485 | +it.live("a code minted with an access level's scopes approves that access", () => | | 486 | + withRoutes((handler, auth) => | | 487 | + Effect.gen(function* () { | | 488 | + const params = authorizeParams(yield* registeredClientId(handler)); | | 489 | + for (const access of AuthMcpClientAccess.literals) { | | 490 | + const code = yield* auth.issuePairingCredential({ scopes: [...mcpClientScopes(access)] }); | | 491 | + const approval = yield* decide(handler, params, { | | 492 | + _tag: "pairing-code", | | 493 | + access, | | 494 | + code: code.credential, | | 495 | + }); | | 496 | + expect(approval.status, access).toBe(200); | | 497 | + } | | 498 | + }), | | 499 | + ), | | 500 | +); | | 501 | + | 483 | 502 | it.live("one-click approves only access the browser session holds the scopes for", () => | 484 | 503 | withRoutes((handler, auth) => | 485 | 504 | Effect.gen(function* () { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/auth/McpOAuth.ts +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,7 @@ import { | 14 | 14 | AuthOrchestrationOperateScope, | 15 | 15 | AuthOrchestrationReadScope, | 16 | 16 | MCP_PEER_LINK_SOFTWARE_ID, | | 17 | + mcpClientScopes, | 17 | 18 | } from "@t3tools/contracts"; | 18 | 19 | import { encodeOAuthScope } from "@t3tools/shared/oauthScope"; | 19 | 20 | import * as Clock from "effect/Clock"; | @@ -436,9 +437,7 @@ const make = Effect.gen(function* () { | 436 | 437 | if ( | 437 | 438 | session === undefined || | 438 | 439 | !timingSafeEqualBase64Url(decision.csrfToken, session.csrfToken) || | 439 | | - !EnvironmentAuth.mcpClientScopes(decision.access).every((scope) => | 440 | | - session.scopes.includes(scope), | 441 | | - ) | | 440 | + !mcpClientScopes(decision.access).every((scope) => session.scopes.includes(scope)) | 442 | 441 | ) { | 443 | 442 | return yield* new McpOAuthPageError({ | 444 | 443 | description: "Your session cannot approve this request. Enter a pairing code instead.", | @@ -523,7 +522,7 @@ const make = Effect.gen(function* () { | 523 | 522 | access_token: issued.token, | 524 | 523 | token_type: "Bearer", | 525 | 524 | expires_in: Math.max(0, Math.floor((issued.expiresAt.epochMilliseconds - now) / 1000)), | 526 | | - scope: encodeOAuthScope(EnvironmentAuth.mcpClientScopes(pending.access)), | | 525 | + scope: encodeOAuthScope(mcpClientScopes(pending.access)), | 527 | 526 | }; | 528 | 527 | }, | 529 | 528 | ); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/auth/mcpOAuthHttp.ts +2-4Lines changed: 2 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,14 +3,14 @@ import { | 3 | 3 | type AuthMcpAuthorizationRequest, | 4 | 4 | AuthMcpClientAccess, | 5 | 5 | EnvironmentHttpApi, | | 6 | + mcpClientScopes, | 6 | 7 | } from "@t3tools/contracts"; | 7 | 8 | import * as Effect from "effect/Effect"; | 8 | 9 | import * as Result from "effect/Result"; | 9 | 10 | import { HttpServerRequest, HttpServerResponse } from "effect/http"; | 10 | 11 | import * as HttpEffect from "effect/http/HttpEffect"; | 11 | 12 | import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder"; | 12 | 13 |
| 13 | | -import * as EnvironmentAuth from "./EnvironmentAuth.ts"; | 14 | 14 | import * as McpOAuth from "./McpOAuth.ts"; | 15 | 15 | import { renderErrorPage } from "./mcpOAuthHtml.ts"; | 16 | 16 |
| @@ -121,9 +121,7 @@ export const layer = HttpApiBuilder.group( | 121 | 121 | : { | 122 | 122 | csrfToken: session.csrfToken, | 123 | 123 | oneClickAccess: AuthMcpClientAccess.literals.filter((access) => | 124 | | - EnvironmentAuth.mcpClientScopes(access).every((scope) => | 125 | | - session.scopes.includes(scope), | 126 | | - ), | | 124 | + mcpClientScopes(access).every((scope) => session.scopes.includes(scope)), | 127 | 125 | ), | 128 | 126 | }), | 129 | 127 | }; | |
|