fix(context-hub): filtrage per-agent scope infra (bruit mcp-nas non pertinent pour Gemini/Hermes) + purge cle obsolete mcp_nas_heredoc_piege_confirme

This commit is contained in:
2026-08-16 21:34:54 +00:00
parent 54047cd5da
commit 39ee17dcac
+6 -6
View File
@@ -2,7 +2,7 @@ import json
from fastapi import APIRouter, Depends, HTTPException, Request from fastapi import APIRouter, Depends, HTTPException, Request
from app.auth import get_current_agent from app.auth import get_current_agent
from app.scopes import has_scope_access, ALL_SCOPES from app.scopes import has_scope_access, ALL_SCOPES
from app.models import get_rule, get_all_rules, get_all_ports, add_audit_log, set_rule from app.models import get_rule, get_all_rules, get_all_ports, add_audit_log, set_rule, filter_content_for_agent
router = APIRouter(prefix="/api") router = APIRouter(prefix="/api")
@@ -21,7 +21,7 @@ async def get_scope_rules(scope: str, request: Request, agent: str = Depends(get
if not rule: if not rule:
raise HTTPException(status_code=404, detail="Scope not found") raise HTTPException(status_code=404, detail="Scope not found")
return rule return filter_content_for_agent(rule, agent)
@router.get("/ports") @router.get("/ports")
async def get_ports_registry(request: Request, agent: str = Depends(get_current_agent)): async def get_ports_registry(request: Request, agent: str = Depends(get_current_agent)):
@@ -42,10 +42,10 @@ async def search_rules(q: str, request: Request, agent: str = Depends(get_curren
for scope in ALL_SCOPES: for scope in ALL_SCOPES:
if has_scope_access(agent, scope): if has_scope_access(agent, scope):
content = all_rules.get(scope, {}) scope_content = filter_content_for_agent(all_rules.get(scope, {}), agent)
# Basic string matching in JSON serialization # Basic string matching in JSON serialization
if q.lower() in json.dumps(content).lower(): if q.lower() in json.dumps(scope_content).lower():
results[scope] = content results[scope] = scope_content
return results return results
@@ -70,6 +70,6 @@ async def get_agent_context(request: Request, agent: str = Depends(get_current_a
result = {} result = {}
for scope in ALL_SCOPES: for scope in ALL_SCOPES:
if has_scope_access(agent, scope): if has_scope_access(agent, scope):
result[scope] = all_rules.get(scope, {}) result[scope] = filter_content_for_agent(all_rules.get(scope, {}), agent)
ports = await get_all_ports() ports = await get_all_ports()
return {"agent": agent, "scopes": result, "ports": ports} return {"agent": agent, "scopes": result, "ports": ports}