GeezerVison is showing github.com — feat(server): honor withheld agent browser access in the v2 runtime · pingdotgg/t3code@2e42519
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpProviderSession.ts +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,13 @@ export interface McpProviderSessionConfig { | 7 | 7 | readonly providerInstanceId: ProviderInstanceId; | 8 | 8 | readonly endpoint: string; | 9 | 9 | readonly authorizationHeader: string; | | 10 | + /** | | 11 | + * Whether this credential includes the "preview" capability. Adapters read | | 12 | + * it to keep developer instructions truthful: when the user withholds agent | | 13 | + * browser access, the prompt must not advertise `preview_*` tools that every | | 14 | + * call would reject. | | 15 | + */ | | 16 | + readonly browserToolsAvailable: boolean; | 10 | 17 | } | 11 | 18 |
| 12 | 19 | const sessionsByThread = new Map<ThreadId, McpProviderSessionConfig>(); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpSessionRegistry.testkit.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ export const layer = Layer.succeed( | 16 | 16 | providerInstanceId, | 17 | 17 | endpoint: "http://127.0.0.1/mcp", | 18 | 18 | authorizationHeader: `Bearer mcp-test:${threadId}`, | | 19 | + browserToolsAvailable: true, | 19 | 20 | }, | 20 | 21 | }), | 21 | 22 | resolve: () => Effect.succeed(undefined), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpSessionRegistry.ts +15-1Lines changed: 15 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,12 @@ import * as McpProviderSession from "./McpProviderSession.ts"; | 14 | 14 | export interface McpCredentialRequest { | 15 | 15 | readonly threadId: ThreadId; | 16 | 16 | readonly providerInstanceId: ProviderInstanceId; | | 17 | + /** | | 18 | + * When false, the credential is minted without the "preview" capability so | | 19 | + * the user's choice to withhold agent browser access holds everywhere the | | 20 | + * token is honored (#7083). Defaults to full access. | | 21 | + */ | | 22 | + readonly browserToolsAvailable?: boolean; | 17 | 23 | } | 18 | 24 |
| 19 | 25 | export interface McpIssuedCredential { | @@ -123,12 +129,19 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* ( | 123 | 129 | const providerSessionId = yield* crypto.randomUUIDv4.pipe(Effect.orDie); | 124 | 130 | const rawToken = yield* crypto.randomBytes(32).pipe(Effect.map(tokenFromBytes), Effect.orDie); | 125 | 131 | const tokenHash = yield* hashToken(rawToken); | | 132 | + const browserToolsAvailable = request.browserToolsAvailable ?? true; | 126 | 133 | const scope: McpInvocationContext.McpInvocationScope = { | 127 | 134 | environmentId, | 128 | 135 | threadId: ThreadId.make(request.threadId), | 129 | 136 | providerSessionId, | 130 | 137 | providerInstanceId: ProviderInstanceId.make(request.providerInstanceId), | 131 | | - capabilities: new Set(McpInvocationContext.ALL_MCP_CAPABILITIES), | | 138 | + capabilities: new Set( | | 139 | + browserToolsAvailable | | 140 | + ? McpInvocationContext.ALL_MCP_CAPABILITIES | | 141 | + : McpInvocationContext.ALL_MCP_CAPABILITIES.filter( | | 142 | + (capability) => capability !== "preview", | | 143 | + ), | | 144 | + ), | 132 | 145 | issuedAt, | 133 | 146 | }; | 134 | 147 | yield* SynchronizedRef.update(state, ({ records }) => { | @@ -144,6 +157,7 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* ( | 144 | 157 | providerInstanceId: scope.providerInstanceId, | 145 | 158 | endpoint, | 146 | 159 | authorizationHeader: `Bearer ${rawToken}`, | | 160 | + browserToolsAvailable, | 147 | 161 | }, | 148 | 162 | }; | 149 | 163 | }, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1149,6 +1149,7 @@ describe("AcpAdapterV2", () => { | 1149 | 1149 | providerInstanceId: instanceId, | 1150 | 1150 | endpoint: "http://127.0.0.1:43123/mcp", | 1151 | 1151 | authorizationHeader: "Bearer target-thread-token", | | 1152 | + browserToolsAvailable: true, | 1152 | 1153 | }); | 1153 | 1154 | yield* Effect.addFinalizer(() => | 1154 | 1155 | Effect.sync(() => McpProviderSession.clearMcpProviderSession(targetThreadId)), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -345,6 +345,7 @@ describe("ClaudeAdapterV2 MCP query overrides", () => { | 345 | 345 | providerInstanceId: ProviderInstanceId.make("claudeAgent"), | 346 | 346 | endpoint: "http://127.0.0.1:43123/mcp", | 347 | 347 | authorizationHeader: "Bearer secret-claude-token", | | 348 | + browserToolsAvailable: true, | 348 | 349 | }); | 349 | 350 | try { | 350 | 351 | run(); | @@ -480,6 +481,7 @@ describe("ClaudeAdapterV2 MCP query overrides", () => { | 480 | 481 | providerInstanceId: ProviderInstanceId.make("claudeAgent"), | 481 | 482 | endpoint: "http://127.0.0.1:43123/mcp", | 482 | 483 | authorizationHeader: "Bearer rotated-claude-token", | | 484 | + browserToolsAvailable: true, | 483 | 485 | }); | 484 | 486 |
| 485 | 487 | const rotatedKey = claudeEffectiveQueryPolicyKey( | @@ -510,6 +512,7 @@ describe("ClaudeAdapterV2 native protocol logging", () => { | 510 | 512 | providerInstanceId: ProviderInstanceId.make("claudeAgent"), | 511 | 513 | endpoint: "http://127.0.0.1:43123/mcp", | 512 | 514 | authorizationHeader: "Bearer secret-claude-token", | | 515 | + browserToolsAvailable: true, | 513 | 516 | }); | 514 | 517 |
| 515 | 518 | try { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -469,6 +469,7 @@ describe("CodexAdapterV2 process spawning", () => { | 469 | 469 | providerInstanceId: ProviderInstanceId.make("codex"), | 470 | 470 | endpoint: "http://127.0.0.1:43123/mcp", | 471 | 471 | authorizationHeader: "Bearer secret-codex-token", | | 472 | + browserToolsAvailable: true, | 472 | 473 | }); | 473 | 474 |
| 474 | 475 | try { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts +8-6Lines changed: 8 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,8 +51,8 @@ import { resolveAttachmentPath } from "../../attachmentStore.ts"; | 51 | 51 | import { getCodexServiceTierOptionValue } from "../../codexModelOptions.ts"; | 52 | 52 | import { ServerConfig } from "../../config.ts"; | 53 | 53 | import { | 54 | | - CODEX_DEFAULT_MODE_DEVELOPER_INSTRUCTIONS, | 55 | | - CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS, | | 54 | + codexDefaultModeDeveloperInstructions, | | 55 | + codexPlanModeDeveloperInstructions, | 56 | 56 | } from "../../provider/CodexDeveloperInstructions.ts"; | 57 | 57 | import { | 58 | 58 | materializeCodexShadowHome, | @@ -578,6 +578,7 @@ export function buildCodexTurnStartParams(input: { | 578 | 578 | readonly runtimePolicy: ProviderAdapterV2RuntimePolicy; | 579 | 579 | readonly modelSelection: ModelSelection; | 580 | 580 | readonly hasT3Mcp?: boolean; | | 581 | + readonly browserToolsAvailable?: boolean; | 581 | 582 | }) { | 582 | 583 | return Effect.gen(function* () { | 583 | 584 | const runtimeModeDefaults = codexRuntimeModeTurnDefaults(input.runtimePolicy.runtimeMode); | @@ -600,8 +601,8 @@ export function buildCodexTurnStartParams(input: { | 600 | 601 | input.hasT3Mcp !== true | 601 | 602 | ? undefined | 602 | 603 | : input.runtimePolicy.interactionMode === "plan" | 603 | | - ? CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS | 604 | | - : CODEX_DEFAULT_MODE_DEVELOPER_INSTRUCTIONS; | | 604 | + ? codexPlanModeDeveloperInstructions(input.browserToolsAvailable ?? true) | | 605 | + : codexDefaultModeDeveloperInstructions(input.browserToolsAvailable ?? true); | 605 | 606 | const collaborationMode: CodexSchema.ClientRequest__CollaborationMode | undefined = | 606 | 607 | input.runtimePolicy.interactionMode !== "plan" && developerInstructions === undefined | 607 | 608 | ? undefined | @@ -4393,13 +4394,14 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi | 4393 | 4394 | const threadId = yield* getNativeThreadId(turnInput.providerThread); | 4394 | 4395 |
| 4395 | 4396 | const codexInput = yield* toCodexInput(turnInput); | | 4397 | + const mcpSession = McpProviderSession.readMcpProviderSession(turnInput.threadId); | 4396 | 4398 | const turnStartParams = yield* buildCodexTurnStartParams({ | 4397 | 4399 | nativeThreadId: threadId, | 4398 | 4400 | codexInput, | 4399 | 4401 | runtimePolicy: turnInput.runtimePolicy, | 4400 | 4402 | modelSelection: turnInput.modelSelection, | 4401 | | - hasT3Mcp: | 4402 | | - McpProviderSession.readMcpProviderSession(turnInput.threadId) !== undefined, | | 4403 | + hasT3Mcp: mcpSession !== undefined, | | 4404 | + browserToolsAvailable: mcpSession?.browserToolsAvailable ?? true, | 4403 | 4405 | }); | 4404 | 4406 | yield* Ref.update(pendingRootTurns, (current) => { | 4405 | 4407 | const updated = new Map(current); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.test.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -119,6 +119,7 @@ describe("CursorAdapterV2", () => { | 119 | 119 | providerInstanceId: ProviderInstanceId.make("cursor"), | 120 | 120 | endpoint: "http://127.0.0.1:43123/mcp", | 121 | 121 | authorizationHeader: "Bearer secret-cursor-mcp-token", | | 122 | + browserToolsAvailable: true, | 122 | 123 | }); | 123 | 124 |
| 124 | 125 | try { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderSessionManager.test.ts +56Lines changed: 56 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,7 @@ import { ServerEnvironment } from "../environment/ServerEnvironment.ts"; | 29 | 29 | import * as McpProviderSession from "../mcp/McpProviderSession.ts"; | 30 | 30 | import * as McpSessionRegistry from "../mcp/McpSessionRegistry.ts"; | 31 | 31 | import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts"; | | 32 | +import * as ServerSettings from "../serverSettings.ts"; | 32 | 33 | import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; | 33 | 34 | import { EventSinkV2, EventSinkWriteError, layer as eventSinkLayer } from "./EventSink.ts"; | 34 | 35 | import { layer as eventStoreLayer } from "./EventStore.ts"; | @@ -338,6 +339,7 @@ function makeTestLayer(input: { | 338 | 339 | readonly failReleaseEventWrites?: boolean; | 339 | 340 | readonly hasPendingBackgroundWork?: Effect.Effect<boolean>; | 340 | 341 | readonly hangSessionScopeClose?: boolean; | | 342 | + readonly serverSettingsLayer?: Layer.Layer<ServerSettings.ServerSettingsService>; | 341 | 343 | }) { | 342 | 344 | const configuredEventSinkLayer = input.failReleaseEventWrites | 343 | 345 | ? FailingReleaseEventSinkLayer | @@ -372,6 +374,7 @@ function makeTestLayer(input: { | 372 | 374 | idAllocatorLayer, | 373 | 375 | TestMcpRegistryLayer, | 374 | 376 | TestStoresLayer, | | 377 | + ...(input.serverSettingsLayer === undefined ? [] : [input.serverSettingsLayer]), | 375 | 378 | ), | 376 | 379 | ), | 377 | 380 | ), | @@ -784,6 +787,59 @@ it.effect( | 784 | 787 | }), | 785 | 788 | ); | 786 | 789 |
| | 790 | +it.effect( | | 791 | + "ProviderSessionManagerV2 withholds the preview capability when agent browser access is off", | | 792 | + () => | | 793 | + Effect.gen(function* () { | | 794 | + const state = yield* Ref.make(emptyState); | | 795 | + const mcpConfigs = yield* Ref.make< | | 796 | + ReadonlyArray<McpProviderSession.McpProviderSessionConfig | undefined> | | 797 | + >([]); | | 798 | + const effect = Effect.gen(function* () { | | 799 | + const eventSink = yield* EventSinkV2; | | 800 | + const idAllocator = yield* IdAllocatorV2; | | 801 | + const manager = yield* ProviderSessionManagerV2; | | 802 | + const registry = yield* McpSessionRegistry.McpSessionRegistry; | | 803 | + const now = yield* DateTime.now; | | 804 | + const threadId = ThreadId.make("thread-provider-session-manager-no-browser"); | | 805 | + const providerSessionId = yield* idAllocator.allocate.providerSession({ | | 806 | + providerInstanceId: modelSelection.instanceId, | | 807 | + threadId, | | 808 | + }); | | 809 | + | | 810 | + yield* eventSink.write({ | | 811 | + events: [yield* makeThreadCreatedEvent({ idAllocator, threadId, now })], | | 812 | + }); | | 813 | + yield* manager.open({ | | 814 | + threadId, | | 815 | + providerSessionId, | | 816 | + modelSelection, | | 817 | + runtimePolicy, | | 818 | + }); | | 819 | + | | 820 | + const captured = (yield* Ref.get(mcpConfigs))[0]; | | 821 | + assert.isDefined(captured); | | 822 | + assert.equal(captured?.browserToolsAvailable, false); | | 823 | + const token = captured?.authorizationHeader.replace(/^Bearer\s+/, ""); | | 824 | + const resolved = yield* registry.resolve(token!); | | 825 | + assert.deepEqual(resolved?.capabilities, new Set(["orchestration", "worktree"])); | | 826 | + | | 827 | + yield* manager.close(providerSessionId); | | 828 | + }); | | 829 | + | | 830 | + yield* effect.pipe( | | 831 | + Effect.provide( | | 832 | + makeTestLayer({ | | 833 | + state, | | 834 | + idleTimeoutMs: 1_000, | | 835 | + mcpConfigs, | | 836 | + serverSettingsLayer: ServerSettings.layerTest({ enableAgentBrowserAccess: false }), | | 837 | + }), | | 838 | + ), | | 839 | + ); | | 840 | + }), | | 841 | +); | | 842 | + | 787 | 843 | it.effect("ProviderSessionManagerV2 revokes MCP credentials when release persistence fails", () => | 788 | 844 | Effect.gen(function* () { | 789 | 845 | const state = yield* Ref.make(emptyState); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderSessionManager.ts +29-1Lines changed: 29 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,6 +24,7 @@ import * as Scope from "effect/Scope"; | 24 | 24 | import * as Stream from "effect/Stream"; | 25 | 25 |
| 26 | 26 | import * as McpProviderSession from "../mcp/McpProviderSession.ts"; | | 27 | +import * as ServerSettings from "../serverSettings.ts"; | 27 | 28 | import * as McpSessionRegistry from "../mcp/McpSessionRegistry.ts"; | 28 | 29 | import { EventSinkV2 } from "./EventSink.ts"; | 29 | 30 | import { IdAllocatorV2 } from "./IdAllocator.ts"; | @@ -264,6 +265,28 @@ export const layerWithOptions = ( | 264 | 265 | Effect.gen(function* () { | 265 | 266 | const registry = yield* ProviderAdapterRegistryV2; | 266 | 267 | const mcpSessionRegistry = yield* McpSessionRegistry.McpSessionRegistry; | | 268 | + /** | | 269 | + * Optional so the many focused tests that assemble this layer by hand do | | 270 | + * not each need a settings stub; the production composition always | | 271 | + * provides it. When present, an unreadable settings file withholds | | 272 | + * browser access rather than granting it — an explicit "off" silently | | 273 | + * becoming "on" would violate the user's stated choice, whereas the | | 274 | + * reverse costs an agent one toolset and is visible immediately (#7083). | | 275 | + */ | | 276 | + const serverSettings = yield* Effect.serviceOption(ServerSettings.ServerSettingsService); | | 277 | + const agentBrowserAccessEnabled = Option.match(serverSettings, { | | 278 | + onNone: () => Effect.succeed(true), | | 279 | + onSome: (settings) => | | 280 | + settings.getSettings.pipe( | | 281 | + Effect.map((resolved) => resolved.enableAgentBrowserAccess), | | 282 | + Effect.catch((cause) => | | 283 | + Effect.logWarning( | | 284 | + "Could not read server settings; withholding agent browser access for this session.", | | 285 | + { cause }, | | 286 | + ).pipe(Effect.as(false)), | | 287 | + ), | | 288 | + ), | | 289 | + }); | 267 | 290 | const eventSink = yield* EventSinkV2; | 268 | 291 | const idAllocator = yield* IdAllocatorV2; | 269 | 292 | const projectionStore = yield* ProjectionStoreV2; | @@ -330,6 +353,7 @@ export const layerWithOptions = ( | 330 | 353 | // the credential it started with, so a thread that detaches and | 331 | 354 | // re-attaches across a workspace handoff must come back to the | 332 | 355 | // same token or the process's tool calls fail auth. | | 356 | + const browserToolsAvailable = yield* agentBrowserAccessEnabled; | 333 | 357 | const existing = McpProviderSession.readMcpProviderSession(threadId); | 334 | 358 | if (existing !== undefined) { | 335 | 359 | // Reserve before the async resolve so a release cannot | @@ -340,7 +364,10 @@ export const layerWithOptions = ( | 340 | 364 | if ( | 341 | 365 | resolved !== undefined && | 342 | 366 | resolved.threadId === threadId && | 343 | | - resolved.providerInstanceId === providerInstanceId | | 367 | + resolved.providerInstanceId === providerInstanceId && | | 368 | + // A flipped browser-access setting must not survive through | | 369 | + // credential reuse: rotate so the new scope reflects it. | | 370 | + resolved.capabilities.has("preview") === browserToolsAvailable | 344 | 371 | ) { | 345 | 372 | return { mcpCredentialId: existing.providerSessionId, issued: false }; | 346 | 373 | } | @@ -350,6 +377,7 @@ export const layerWithOptions = ( | 350 | 377 | const credential = yield* mcpSessionRegistry.issue({ | 351 | 378 | threadId, | 352 | 379 | providerInstanceId, | | 380 | + browserToolsAvailable, | 353 | 381 | }); | 354 | 382 | McpProviderSession.setMcpProviderSession(credential.config); | 355 | 383 | reserveMcpCredential(threadId, credential.config.providerSessionId); | |
|