Skip to content

feat(copilot): provide accessible workspaces to agents - #6222

Closed
j15z wants to merge 1 commit into
stagingfrom
feat/accessible-workspaces-context
Closed

feat(copilot): provide accessible workspaces to agents#6222
j15z wants to merge 1 commit into
stagingfrom
feat/accessible-workspaces-context

Conversation

@j15z

@j15z j15z commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Agents now receive the authenticated user's active accessible workspaces as { id, name, permission } runtime context, allowing main agents and subagents to answer workspace-access questions without another lookup. The list uses effective permissions, degrades safely if the informational lookup fails, and is omitted for external inbox senders so the workspace owner's other workspaces cannot leak.

Companion runtime consumer: simstudioai/mothership#391

Deployment order: merge and deploy Mothership first, then Sim.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

  • bunx vitest run lib/copilot/chat/accessible-workspaces.test.ts lib/copilot/chat/payload.test.ts lib/copilot/chat/post.test.ts app/api/mothership/execute/route.test.ts lib/mothership/inbox/executor.test.ts — 43 tests passed
  • bunx --bun tsc --noEmit --pretty false
  • bun run check:api-validation

Review focus: authenticated-user scoping and omission of cross-workspace context for external inbox senders.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Screenshots/Videos

Not applicable — agent runtime context only.

@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 3, 2026 7:44pm

Request Review

@cursor

cursor Bot commented Aug 3, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Adds cross-workspace metadata to agent payloads for authenticated users; inbox correctly gates omission for external senders, but any bug in actor scoping could leak workspace names/permissions beyond the active workspace.

Overview
Agents now receive accessible workspace context (id, name, permission) on outbound copilot/mothership requests so they can answer workspace-access questions without another lookup.

A new getAccessibleWorkspacesForCopilot helper loads active workspaces via listAccessibleWorkspaceRowsForUser, sorts them by name, and returns [] on lookup failure. buildCopilotRequestPayload accepts optional accessibleWorkspaces and only includes the field when non-empty.

Interactive chat (post.ts) fetches accessible workspaces in parallel with other prep and forwards them into payload construction for workflow and workspace branches. Headless mothership execute and inbox execution for authenticated members do the same. External inbox senders (owner fallback, no secretActorUserId) skip the lookup and omit accessibleWorkspaces so the owner's other workspaces are not leaked.

Reviewed by Cursor Bugbot for commit d25f790. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Agents now receive a stable list of active workspaces accessible to the authenticated user, including effective permissions, across interactive Copilot and internal Mothership execution paths. The lookup degrades to omitted context on failure and is explicitly skipped for external inbox senders.

  • Adds a shared accessible-workspace projection with deterministic ordering.
  • Passes the context through interactive chat and headless execution payloads.
  • Restricts inbox inclusion to senders resolved as workspace members.
  • Adds focused tests for projection, transport, failure fallback, and inbox omission.

Confidence Score: 5/5

The PR appears safe to merge with the new workspace context scoped to resolved users and omitted for external inbox senders.

The shared lookup filters to active accessible workspaces, computes effective permissions through the established workspace utility, degrades to omitted optional context on failure, and preserves independent authorization checks for actions.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/chat/accessible-workspaces.ts Adds a safely degrading, deterministically sorted projection of active accessible workspaces and effective permissions.
apps/sim/lib/copilot/chat/post.ts Loads the workspace list for the session-authenticated user and forwards it through both interactive Copilot branches.
apps/sim/app/api/mothership/execute/route.ts Adds accessible-workspace context to authenticated headless Mothership execution payloads.
apps/sim/lib/copilot/chat/payload.ts Extends Copilot payload construction to conditionally forward nonempty accessible-workspace lists.
apps/sim/lib/mothership/inbox/executor.ts Includes the list for workspace-member senders while omitting it for external senders using owner execution fallback.

Sequence Diagram

sequenceDiagram
  participant User as Authenticated user
  participant Sim as Sim request handler
  participant DB as Workspace authorization data
  participant Agent as Mothership agent
  Sim->>DB: List active accessible workspaces by authenticated user ID
  DB-->>Sim: id, name, effective permission
  alt Lookup succeeds with results
    Sim->>Agent: Runtime payload with accessibleWorkspaces
  else Lookup fails or returns empty
    Sim->>Agent: Runtime payload without accessibleWorkspaces
  end
  Note over Sim,Agent: External inbox senders always take the omission path
Loading

Reviews (1): Last reviewed commit: "feat(copilot): send accessible workspace..." | Re-trigger Greptile

@j15z

j15z commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by the focused tool-based approach in #5948.

@j15z

j15z commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #6227, which contains the focused list_user_workspaces update. The platform-agent work in #5948 is stacked on that replacement PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant