diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3c13468..a638ab0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,11 @@ or `minder-plugin scaffold `. 2. Add it as `/__init__.py`, importing from `minder_plugin_sdk`. Declare a `register()` returning `PluginMetadata`, and any of `CONFIG_SCHEMA` / `ACTIONS` - / `AI_TOOLS` / `DISPLAY` / `REQUIRES` you need. + / `AI_TOOLS` / `DISPLAY` / `REQUIRES` you need. Every `AI_TOOLS` entry + declares its `effect` (`read` / `write` / `send` / `destructive`), and + `idempotent` / `hosts` / argument `sensitivity` where they apply (see the + SDK README, "Tool effects"). `tests/test_tool_effects.py` fails on a tool + with no effect or one its name, method or arguments contradict. 3. Validate locally: ```bash pip install -e ".[dev]" diff --git a/arxiv/__init__.py b/arxiv/__init__.py index a505592..7b08e27 100644 --- a/arxiv/__init__.py +++ b/arxiv/__init__.py @@ -81,6 +81,7 @@ class ArxivPlugin(PluginBase): "properties": { "query": { "type": "string", + "sensitivity": "free_text", "description": ( "The research topic or keywords, e.g. " "'retrieval augmented generation'." @@ -95,6 +96,9 @@ class ArxivPlugin(PluginBase): }, "action": "search_papers", "method": "GET", + "effect": "read", + "idempotent": True, + "hosts": ["export.arxiv.org"], }, ] diff --git a/crypto/__init__.py b/crypto/__init__.py index 423485e..cd6b17b 100644 --- a/crypto/__init__.py +++ b/crypto/__init__.py @@ -122,6 +122,9 @@ class CryptoPlugin: }, "action": "get_price", "method": "GET", + "effect": "read", + "idempotent": True, + "hosts": ["query1.finance.yahoo.com"], }, ] diff --git a/frankfurter/__init__.py b/frankfurter/__init__.py index 45b201b..6d04cd0 100644 --- a/frankfurter/__init__.py +++ b/frankfurter/__init__.py @@ -83,7 +83,7 @@ class FrankfurterPlugin(PluginBase): "parameters": { "type": "object", "properties": { - "amount": {"type": "number"}, + "amount": {"type": "number", "sensitivity": "amount"}, "from_currency": {"type": "string"}, "to_currency": {"type": "string"}, }, @@ -91,6 +91,9 @@ class FrankfurterPlugin(PluginBase): }, "action": "convert", "method": "GET", + "effect": "read", + "idempotent": True, + "hosts": ["api.frankfurter.dev"], }, ] diff --git a/github/__init__.py b/github/__init__.py index 31fea59..31ffe11 100644 --- a/github/__init__.py +++ b/github/__init__.py @@ -101,6 +101,9 @@ class GitHubPlugin(PluginBase): }, "action": "get_repo_stats", "method": "GET", + "effect": "read", + "idempotent": True, + "hosts": ["api.github.com"], }, ] diff --git a/hackernews/__init__.py b/hackernews/__init__.py index fcdf256..6605664 100644 --- a/hackernews/__init__.py +++ b/hackernews/__init__.py @@ -73,6 +73,9 @@ class HackerNewsPlugin(PluginBase): }, "action": "top_stories", "method": "GET", + "effect": "read", + "idempotent": True, + "hosts": ["hacker-news.firebaseio.com"], }, ] diff --git a/network/__init__.py b/network/__init__.py index e547642..c43cdee 100644 --- a/network/__init__.py +++ b/network/__init__.py @@ -169,6 +169,11 @@ class NetworkPlugin: ), "parameters": {"type": "object", "properties": {}, "required": []}, "action": "scan", + # Discover-only: probes the operator-configured targets (nmap/SNMP gets) + # and caches the result in memory; it writes to no store. No `hosts`: + # the targets are config (NETWORK_SCAN_TARGETS), not code. + "effect": "read", + "idempotent": True, }, { "name": "network_reconcile", @@ -178,6 +183,14 @@ class NetworkPlugin: ), "parameters": {"type": "object", "properties": {}, "required": []}, "action": "reconcile", + # Rewrites + reloads the telegraf managed region, upserts the + # inventory/graph, publishes change events, and DELETEs stale-down + # inventory rows and prunes graph nodes past the retention window -- + # the deletions make it destructive. Not idempotent: change events + # and pruning depend on the previous cycle and the clock. No `hosts`: + # the scan targets and backend URLs are config, not code. + "effect": "destructive", + "idempotent": False, }, ] diff --git a/news/__init__.py b/news/__init__.py index bae6c3f..0c3c32c 100644 --- a/news/__init__.py +++ b/news/__init__.py @@ -182,6 +182,10 @@ class NewsPlugin: }, "action": "get_news", "method": "GET", + # No `hosts`: it reads the operator-configured NEWS_FEEDS URLs, so the + # reachable hosts are config, not code (covered by EGRESS = "public"). + "effect": "read", + "idempotent": True, }, ] diff --git a/openlibrary/__init__.py b/openlibrary/__init__.py index 8e71563..7c55bbc 100644 --- a/openlibrary/__init__.py +++ b/openlibrary/__init__.py @@ -80,6 +80,7 @@ class OpenLibraryPlugin(PluginBase): "properties": { "query": { "type": "string", + "sensitivity": "free_text", "description": ( "Title, topic, or author, e.g. " "'distributed systems' or 'Ursula K. Le Guin'." @@ -94,6 +95,9 @@ class OpenLibraryPlugin(PluginBase): }, "action": "search_books", "method": "GET", + "effect": "read", + "idempotent": True, + "hosts": ["openlibrary.org"], }, ] diff --git a/portfolio/__init__.py b/portfolio/__init__.py index d6fda6e..8b7ee51 100644 --- a/portfolio/__init__.py +++ b/portfolio/__init__.py @@ -132,6 +132,11 @@ class PortfolioPlugin: # from the JWT, never supplied by the model/caller. "parameters": {"type": "object", "properties": {}, "required": []}, "action": "get_value", + # Reads the caller's own series back from the platform time-series + # store; it makes no outbound connection, hence `hosts: []`. + "effect": "read", + "idempotent": True, + "hosts": [], }, ] diff --git a/pyproject.toml b/pyproject.toml index 019cb78..a5b6fd5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,12 +16,15 @@ py-modules = [] [project.optional-dependencies] dev = [ # Pinned past v0.1.0 to a specific commit (not a new tag -- this repo's - # own CHANGELOG: no routine version bumps pre-1.0). 0861d974 is plugin-sdk - # #43 (platform context, contract v2): self.ctx / bind_context, the - # CONTRACT_VERSION / MANAGES / EGRESS / TIMESERIES declarations and their - # validator rules, FakePlatformContext. It still carries the package-style - # plugin validate/inspect fix `network` needs (plugin-sdk#26). - "minder-plugin-sdk @ git+https://github.com/minderhq/plugin-sdk@0861d974ed16d5ae6f60c5c4a6f5cb875dded374", + # own CHANGELOG: no routine version bumps pre-1.0). f44873fc is plugin-sdk + # #50 (tool effect classes): the AI_TOOLS `effect`, `idempotent`, + # per-argument `sensitivity` and `hosts` fields, which `minder-plugin + # validate` checks (errors on invalid values, warnings on a missing or + # contradicted effect). It builds on plugin-sdk #43 (platform context, + # contract v2: self.ctx / bind_context, the CONTRACT_VERSION / MANAGES / + # EGRESS / TIMESERIES declarations, FakePlatformContext) and still carries + # the package-style plugin validate/inspect fix `network` needs (#26). + "minder-plugin-sdk @ git+https://github.com/minderhq/plugin-sdk@f44873fcada50f17cc38d26089837d4d1a6227ec", "httpx>=0.27", "defusedxml>=0.7", "pytest>=8", diff --git a/tefas_funds/__init__.py b/tefas_funds/__init__.py index f52dbf0..fa9ac7b 100644 --- a/tefas_funds/__init__.py +++ b/tefas_funds/__init__.py @@ -124,6 +124,9 @@ class TefasPlugin: }, "action": "get_fund_price", "method": "GET", + "effect": "read", + "idempotent": True, + "hosts": ["www.tefas.gov.tr"], }, ] diff --git a/tests/test_tool_effects.py b/tests/test_tool_effects.py new file mode 100644 index 0000000..5adbfb8 --- /dev/null +++ b/tests/test_tool_effects.py @@ -0,0 +1,34 @@ +"""Every AI tool in the catalog declares its effect class (plugin-sdk#50). + +``minder-plugin validate`` only *warns* about a tool with no ``effect`` or a +declaration that the tool's name, method or arguments contradict, so CI would +pass with either. This makes both a failure, and pins the tools that are not +plain reads so a change to them is a deliberate one. +""" + +import importlib + +import pytest + +from minder_plugin_sdk.tool_effects import tool_effect_warnings + +from test_catalog import _plugin_class, _plugin_packages + +# Every tool not listed here is a pure read. +_NOT_READ = {("network", "network_reconcile"): "destructive"} + + +@pytest.mark.parametrize("pkg", _plugin_packages()) +def test_tools_declare_an_uncontradicted_effect(pkg): + plugin = _plugin_class(importlib.import_module(pkg))() + assert tool_effect_warnings(plugin) == [] + + +@pytest.mark.parametrize("pkg", _plugin_packages()) +def test_reads_are_idempotent_and_the_rest_are_pinned(pkg): + cls = _plugin_class(importlib.import_module(pkg)) + for tool in getattr(cls, "AI_TOOLS", []) or []: + expected = _NOT_READ.get((pkg, tool["name"]), "read") + assert tool["effect"] == expected, (pkg, tool["name"]) + if expected == "read": + assert tool.get("idempotent") is True, (pkg, tool["name"]) diff --git a/weather/__init__.py b/weather/__init__.py index f6c74ed..edd5f77 100644 --- a/weather/__init__.py +++ b/weather/__init__.py @@ -87,6 +87,7 @@ class WeatherPlugin: "properties": { "location": { "type": "string", + "sensitivity": "free_text", "description": "City name, e.g. 'Istanbul', 'Tokyo', 'Berlin'.", }, }, @@ -94,6 +95,11 @@ class WeatherPlugin: }, "action": "get_weather", "method": "GET", + # The default hosts; an operator can repoint them with WEATHER_API_BASE / + # WEATHER_GEOCODE_BASE (env only, not a tool argument). + "effect": "read", + "idempotent": True, + "hosts": ["geocoding-api.open-meteo.com", "api.open-meteo.com"], }, ] diff --git a/wikipedia/__init__.py b/wikipedia/__init__.py index 02af2ee..e2d22d5 100644 --- a/wikipedia/__init__.py +++ b/wikipedia/__init__.py @@ -73,6 +73,7 @@ class WikipediaPlugin(PluginBase): "properties": { "topic": { "type": "string", + "sensitivity": "free_text", "description": "What to look up, e.g. 'Alan Turing', 'RAG'.", }, }, @@ -80,6 +81,9 @@ class WikipediaPlugin(PluginBase): }, "action": "wiki_summary", "method": "GET", + "effect": "read", + "idempotent": True, + "hosts": ["*.wikipedia.org"], }, ]