Skip to content

feat: scope agent dropdown to current site using site_scope column#946

Merged
chubes4 merged 1 commit intomainfrom
feature/agent-site-scope-filtering
Mar 23, 2026
Merged

feat: scope agent dropdown to current site using site_scope column#946
chubes4 merged 1 commit intomainfrom
feature/agent-site-scope-filtering

Conversation

@chubes4
Copy link
Member

@chubes4 chubes4 commented Mar 23, 2026

Summary

  • Mirrors WordPress core's multisite user scoping pattern — agent queries now default to the current blog_id, returning only agents with matching site_scope OR site_scope IS NULL (network-wide)
  • Fixes agent dropdown showing all agents on all sites — each subsite now sees only its relevant agent(s) plus network-wide agents like Sarai
  • Adds site_scope to REST API response so the frontend knows which site an agent belongs to
  • Fixes access grant fallback in resolve_scoped_agent_id() for non-admin users who don't own an agent but have explicit access grants

Test Results

Verified across all subsites via WP-CLI and REST API:

Site Blog ID Agents Shown
extrachill.com 1 extra-chill-bot (scope=1), sarai (scope=NULL)
events.extrachill.com 7 events-bot (scope=7), sarai (scope=NULL)
studio.extrachill.com 12 roadie (scope=12), sarai (scope=NULL)
wire.extrachill.com 11 wire-bot (scope=11), sarai (scope=NULL)
Unfiltered (all) All 5 agents

Agent test suite: 83 passed, 30 failed (same as main branch — zero regressions).

Files Changed

  • inc/Core/Database/Agents/Agents.phpget_all() accepts optional site_id arg
  • inc/Api/Agents.phphandle_list() passes current blog_id; shape_list_item() includes site_scope
  • inc/Abilities/AgentAbilities.phplistAgents() filters by current site
  • inc/Abilities/PermissionHelper.phpresolve_scoped_agent_id() checks access grants in non-admin fallback

Mirror WordPress core's multisite user scoping pattern: agent queries
default to the current blog_id, returning agents with matching site_scope
OR site_scope IS NULL (network-wide). This ensures each subsite's agent
dropdown shows only relevant agents instead of all agents across the network.

Changes:
- Agents::get_all() accepts optional site_id arg for site_scope filtering
- Api\Agents::handle_list() passes current blog_id for both admin and non-admin paths
- shape_list_item() includes site_scope in REST API response
- AgentAbilities::listAgents() filters by current site
- PermissionHelper::resolve_scoped_agent_id() falls back to access grants
  when user owns no agent (fixes gap for shared agent access)
@chubes4 chubes4 merged commit 32a712d into main Mar 23, 2026
1 check failed
@chubes4 chubes4 deleted the feature/agent-site-scope-filtering branch March 23, 2026 14:38
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