From 649386f0b86ee65790d66da2a3355e7d8c5fedc6 Mon Sep 17 00:00:00 2001 From: architect Date: Fri, 27 Nov 2026 21:09:53 +0300 Subject: [PATCH] [STAGE5] Tool Gateway policy registry + test --- docs/architecture/REGISTRY/tool_gateway.yaml | 27 ++++++++++++++++++++ docs/architecture/STAGE-5.md | 2 +- ops/ai/tests/test_tool_gateway.py | 15 +++++++++++ ops/ai/tool_gateway.py | 18 +++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 docs/architecture/REGISTRY/tool_gateway.yaml create mode 100644 ops/ai/tests/test_tool_gateway.py create mode 100644 ops/ai/tool_gateway.py diff --git a/docs/architecture/REGISTRY/tool_gateway.yaml b/docs/architecture/REGISTRY/tool_gateway.yaml new file mode 100644 index 0000000..3ef8765 --- /dev/null +++ b/docs/architecture/REGISTRY/tool_gateway.yaml @@ -0,0 +1,27 @@ +version: 1 +policy: "agents may use only gateway-listed tools; direct production access is forbidden" +tools: + - name: catalog.read + gateway: http://127.0.0.1:9120/catalog + mode: read + approval: false + - name: status.read + gateway: http://127.0.0.1:9120/status + mode: read + approval: false + - name: notify.send + gateway: http://127.0.0.1:9120/notify + mode: write + approval: true + - name: media.read + gateway: http://127.0.0.1:9180/v1/media + mode: read + approval: false + - name: events.read + gateway: http://127.0.0.1:9180/v1/events + mode: read + approval: false + - name: audit.write + gateway: http://127.0.0.1:9160/api/sprint/status + mode: write + approval: true diff --git a/docs/architecture/STAGE-5.md b/docs/architecture/STAGE-5.md index 0dc7042..3d7bbd8 100644 --- a/docs/architecture/STAGE-5.md +++ b/docs/architecture/STAGE-5.md @@ -26,7 +26,7 @@ GET /v1/models | S5-03 | Evals / golden set | open | | S5-04 | Memory | open | | S5-05 | Night Shift | open | -| S5-06 | Tool Gateway / agent approvals | open | +| S5-06 | Tool Gateway / agent approvals | in_progress: policy registry, no enforcement | | S5-07 | Gate G5 | open | ## Ограничение diff --git a/ops/ai/tests/test_tool_gateway.py b/ops/ai/tests/test_tool_gateway.py new file mode 100644 index 0000000..6dbfdf5 --- /dev/null +++ b/ops/ai/tests/test_tool_gateway.py @@ -0,0 +1,15 @@ +import sys, unittest +from pathlib import Path +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +from tool_gateway import load_tools + +class GatewayTests(unittest.TestCase): + def test_tools_have_gateway(self): + tools = load_tools() + self.assertGreaterEqual(len(tools), 3) + for t in tools: + self.assertTrue(t["gateway"].startswith("http")) + self.assertFalse(t.get("direct_prod", False)) + +if __name__ == "__main__": + unittest.main() diff --git a/ops/ai/tool_gateway.py b/ops/ai/tool_gateway.py new file mode 100644 index 0000000..6c73e58 --- /dev/null +++ b/ops/ai/tool_gateway.py @@ -0,0 +1,18 @@ +"""Read-only Tool Gateway policy registry (Stage 5).""" +from pathlib import Path +import yaml + +PATH = Path("/root/buryan-infra/docs/architecture/REGISTRY/tool_gateway.yaml") + + +def load_tools(): + data = yaml.safe_load(PATH.read_text()) + tools = data.get("tools") or [] + for t in tools: + if not t.get("gateway"): + raise ValueError("tool without gateway: %s" % t.get("name")) + if t.get("direct_prod"): + raise ValueError("direct production access forbidden: %s" % t.get("name")) + if t.get("mode") not in ("read", "write"): + raise ValueError("bad mode: %s" % t.get("name")) + return tools