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:
@@ -112,6 +112,27 @@ async def get_all_rules() -> Dict[str, Any]:
|
||||
rows = await cursor.fetchall()
|
||||
return {row[0]: json.loads(row[1]) for row in rows}
|
||||
|
||||
RESTRICTED_KEY = "_agent_only"
|
||||
|
||||
def filter_content_for_agent(content: Optional[Dict[str, Any]], agent_name: str) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Retire du contenu d'un scope les cles marquees reservees a une liste precise
|
||||
d'agents (metadonnee "_agent_only": {cle: [AGENTS...]} dans le JSON stocke).
|
||||
Sert a eviter le bruit non pertinent (ex: pieges mcp-nas, outil exclusif a
|
||||
Claude, envoyes sans filtrage a Gemini/Hermes). Ne modifie jamais le contenu
|
||||
stocke en base -- uniquement la copie renvoyee au consommateur. Sync (pas
|
||||
d'IO), safe a appeler juste apres n'importe quel get_rule/get_all_rules.
|
||||
"""
|
||||
if not content or RESTRICTED_KEY not in content:
|
||||
return content
|
||||
filtered = dict(content)
|
||||
restrictions = filtered.pop(RESTRICTED_KEY, {}) or {}
|
||||
agent_upper = (agent_name or "").upper()
|
||||
for key, allowed_agents in restrictions.items():
|
||||
if key in filtered and agent_upper not in [a.upper() for a in allowed_agents]:
|
||||
filtered.pop(key, None)
|
||||
return filtered
|
||||
|
||||
async def get_all_ports() -> List[Dict[str, Any]]:
|
||||
async with aiosqlite.connect(DB_PATH) as db:
|
||||
db.row_factory = aiosqlite.Row
|
||||
|
||||
Reference in New Issue
Block a user