Add opt-in selected-workspace Context OAuth grants

Merged
SI
3d ago
+1184-39

Adds an explicit selected-workspace Context connection for interactions already requesting mcp:tools. Consent tickets and encrypted grant attribution bind the chosen workspace plus frozen context-workspace-v1 capabilities; refresh keeps that selection. Existing broad, limited and registration grants retain their behavior.

The selected MCP surface exposes only 27 approved Context actions. Execution rejects other tools and other workspaces, preserves the original actor, and rechecks the live grant/membership through the existing Context domain authorization seam. Connection management displays sanitized selection metadata and retains owner-only revocation.

Validation: exact-head full unit suite (10,407 passing), OAuth compatibility (prior CI passed; final successor CI recorded on this PR), production/OAuth types and lint; 87 focused capability/domain tests after review fixes. Exact candidate 8169613e also passed three encrypted PostgreSQL15 tests with raw source verification before/after, dotenv disabled with a synthetic poison control, and confirmed owned worker/process/socket/directory cleanup. Two independent exact-head reviews passed after fixes and the ordinary merge of current main 63eba608. The incoming brief-cache change composes without altering OAuth authority. Late review corrections preserve ticket-bound cancellation after workspace access loss, add selected-route discovery and isolated authority regression coverage, and expose the action set through an immutable membership facade.

Mixed-version safety: selected grants use encrypted extra.context: selected_context_v1, which the pinned pre-selection verifier rejects. Current verification requires that discriminator and valid selected metadata together; legacy records remain unchanged. Exact old-source tests reproduce the earlier broad fallback and now reject newly issued/refreshed selected tokens while the current verifier accepts them. Old rollback can make selected connections unavailable, including management listing, but cannot grant broad access. Do not relabel selected grants as legacy.

Boundaries: membership-only Context authority; graded-role loss and broad business-tool authorization remain open in recoupable/mono#208 and recoupable/mono#212. No migration, real-account/provider acceptance, production configuration change or activation. API1237/1011 schema extraction is not duplicated; production processContextOperation.ts stays unchanged. Deploy this API support before the companion App UI in recoupable/app#2403. Merge remains with the coordinator.

Contributes to recoupable/mono#207; does not close the broader J3 acceptance.