fix(ai): facade backend/tools/api.py (namespace packages, __init__ ignore)
CI / lint (push) Successful in 57s
CI / security (push) Successful in 39s
CI / test (push) Successful in 1m12s
CI / build (push) Successful in 36s
CI / e2e (push) Successful in 10m22s
Desktop Build / build-windows (push) Canceled after 0s
Desktop Build / build-linux (push) Canceled after 0s

Le .gitignore exclut _*.py, donc backend/tools/__init__.py n'etait pas versionne et
la CI echouait a l'import (unknown location). Remplacement par une facade api.py
qui enregistre les outils et reexporte l'API publique. Tests adaptes.
This commit is contained in:
2026-09-11 12:18:35 -04:00
parent 5c1823d6d2
commit 400224a089
3 changed files with 57 additions and 2 deletions
+53
View File
@@ -0,0 +1,53 @@
"""Public facade for the AI tool layer.
Importing this module registers all built-in tools (via
``backend.tools.service``) and re-exports the public API. Consumers (agent
loop, MCP server, tests) should import from here rather than from individual
submodules.
Note: ObsiGate uses implicit namespace packages (no tracked ``__init__.py``,
which ``.gitignore`` excludes via ``_*.py``), hence this explicit facade.
"""
from backend.tools import service as _service # noqa: F401 (registers tools)
from backend.tools.context import (
ToolConfirmationRequired,
ToolContext,
ToolError,
ToolMode,
ToolNotFoundError,
ToolPermissionError,
ToolRisk,
ToolScope,
ToolValidationError,
resolve_safe_path,
)
from backend.tools.registry import (
ToolSpec,
call_tool,
get_tool,
get_tool_schemas,
list_tools,
tool,
)
from backend.tools.schemas import ToolResult
__all__ = [
"ToolConfirmationRequired",
"ToolContext",
"ToolError",
"ToolMode",
"ToolNotFoundError",
"ToolPermissionError",
"ToolResult",
"ToolRisk",
"ToolScope",
"ToolSpec",
"ToolValidationError",
"call_tool",
"get_tool",
"get_tool_schemas",
"list_tools",
"resolve_safe_path",
"tool",
]
+3 -1
View File
@@ -97,7 +97,7 @@ Extraire la logique métier des routes de `backend/main.py` vers des fonctions r
```
backend/tools/
├── __init__.py
├── api.py # façade publique (enregistre les outils, réexporte l'API)
├── context.py # ToolContext (user, allowed_vaults, mode, confirmed)
├── registry.py # décorateur @tool(...) + schémas JSON
├── schemas.py # modèles Pydantic entrée/sortie
@@ -105,6 +105,8 @@ backend/tools/
└── audit.py # journalisation des appels d'outils
```
> ObsiGate utilise des **namespace packages** implicites (aucun `__init__.py` suivi — `.gitignore` exclut `_*.py`). La façade `api.py` joue le rôle de point d'entrée et déclenche l'enregistrement des outils.
### 3.2 Couche 2 — Registry d'outils
Chaque outil déclare : `name`, `description`, `parameters` (JSON Schema), `risk` (`read` | `write` | `dangerous`), `requires_confirmation` (bool), `scopes` (`in_app`, `mcp`).
+1 -1
View File
@@ -10,7 +10,7 @@ from pathlib import Path
import pytest
from backend.tools import (
from backend.tools.api import (
ToolConfirmationRequired,
ToolContext,
ToolError,