From 3631f113621932506d4cf600b48637699d4fe459 Mon Sep 17 00:00:00 2001 From: Master Date: Wed, 1 Jul 2026 12:34:29 +0200 Subject: [PATCH] fix: garde-fou edition base sur label projet au lieu de TYPES_SYSTEME fige - _est_editable() dans trilium_api.py : editable si label projet ou type=projet - tool_update_note + delete_note_safe utilisent ce critere - tool_get_children : filtre TYPES_SYSTEME retire (transparence) Corrige : composants techniques editables, get_children ne les masque plus. Revele par le test Phase 3 (agent bloque sur edition de composant). --- entites_codeversioning.json | 5 +++++ mcp_server.py | 16 ++++------------ trilium_api.py | 21 ++++++++++++++------- 3 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 entites_codeversioning.json diff --git a/entites_codeversioning.json b/entites_codeversioning.json new file mode 100644 index 0000000..0ab2fb4 --- /dev/null +++ b/entites_codeversioning.json @@ -0,0 +1,5 @@ +{ + "Forgejo": "ArTsdwSCqXod", + "Docker": "fLQXL4Tyz7gg", + "GrosseBertha": "PEll7MT00sL9" +} \ No newline at end of file diff --git a/mcp_server.py b/mcp_server.py index 710e294..513a4e9 100644 --- a/mcp_server.py +++ b/mcp_server.py @@ -460,30 +460,22 @@ def tool_get_note(note_id): "contenu": get_note_content(note_id)} def tool_get_children(parent_id): - from trilium_api import TYPES_SYSTEME out = [] for child in get_children(parent_id): cid = child.get("noteId") n = get_note(cid) if not n: continue - tv = _type_systeme(n) - if tv in TYPES_SYSTEME: - out.append({"id": cid, "titre": n.get("title", ""), "type": tv}) + out.append({"id": cid, "titre": n.get("title", ""), "type": _type_systeme(n)}) return {"parent": parent_id, "count": len(out), "notes": out} def tool_update_note(note_id, contenu, format="markdown"): - from trilium_api import TYPES_SYSTEME + from trilium_api import _est_editable note = get_note(note_id) if not note: return {"error": "Note introuvable"} - type_val = None - for a in note.get("attributes", []): - if a.get("type") == "label" and a.get("name") == "type": - type_val = a.get("value") - break - if type_val not in TYPES_SYSTEME: - return {"error": "Refus : note sans type systeme connu (type=%s)" % type_val} + if not _est_editable(note): + return {"error": "Refus : note structurelle protegee (sans label projet)"} if format == "html": body = contenu else: diff --git a/trilium_api.py b/trilium_api.py index 7f2bb6b..9e40aae 100644 --- a/trilium_api.py +++ b/trilium_api.py @@ -138,13 +138,8 @@ def delete_note_safe(note_id: str): note = get_note(note_id) if not note: return (False, "Note introuvable") - type_val = None - for a in note.get("attributes", []): - if a.get("type") == "label" and a.get("name") == "type": - type_val = a.get("value") - break - if type_val not in TYPES_SYSTEME: - return (False, "Refus : note sans type systeme connu (type=%s)" % type_val) + if not _est_editable(note): + return (False, "Refus : note structurelle protegee (sans label projet)") titre = note.get("title", "?") ok = _ea().delete_note(note_id) if ok: @@ -214,3 +209,15 @@ def add_relation_safe(source_id, nom, cible_id): except Exception as e: return (False, "Echec creation relation: %s" % e) return (True, "Relation creee: %s ~%s %s" % (source_id, nom, cible_id)) + + +def _est_editable(note): + """Nouveau critere de garde-fou : une note est editable/supprimable si elle + porte un label projet (note de projet, propriete du projet), ou si son type + est 'projet' lui-meme. Sinon (ontologie, skills universels, dossiers + structurels) elle est protegee par defaut. Remplace TYPES_SYSTEME (liste + figee, desynchronisee de l ontologie a chaque nouvelle classe).""" + labels = {a.get("name"): a.get("value") for a in note.get("attributes", []) if a.get("type") == "label"} + if labels.get("type") == "projet": + return True + return bool(labels.get("projet"))