nutria-plugin 0.7.0__tar.gz → 0.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/CHANGELOG.md +39 -0
  2. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/PKG-INFO +3 -3
  3. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/README.md +2 -2
  4. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/capability-authoring.md +2 -0
  5. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/index.md +1 -1
  6. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/manifest.md +1 -1
  7. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/outside-audience.md +10 -1
  8. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/python-api.md +26 -3
  9. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/quickstart.md +1 -1
  10. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/reviewable-actions.md +45 -4
  11. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/pyproject.toml +1 -1
  12. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/__init__.py +60 -3
  13. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/capabilities.py +26 -12
  14. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/manifest.py +0 -20
  15. nutria_plugin-0.8.0/src/nutria_plugin/prepared_preview.py +530 -0
  16. nutria_plugin-0.8.0/tests/test_audience_contract.py +72 -0
  17. nutria_plugin-0.8.0/tests/test_receipts.py +180 -0
  18. nutria_plugin-0.8.0/tests/test_version.py +15 -0
  19. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/uv.lock +1 -1
  20. nutria_plugin-0.7.0/src/nutria_plugin/prepared_preview.py +0 -163
  21. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/.github/workflows/publish.yml +0 -0
  22. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/.gitignore +0 -0
  23. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/admin-extensions.md +0 -0
  24. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/admin-flows.md +0 -0
  25. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/cli.md +0 -0
  26. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/connection-types.md +0 -0
  27. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/conversation-ownership.md +0 -0
  28. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/migration-6.0.md +0 -0
  29. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/security.md +0 -0
  30. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/docs/skill-format.md +0 -0
  31. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/examples/my-first-plugin/README.md +0 -0
  32. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/examples/my-first-plugin/hooks/hooks.json +0 -0
  33. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/examples/my-first-plugin/plugin.json +0 -0
  34. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/examples/my-first-plugin/settings.schema.json +0 -0
  35. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/bundle.py +0 -0
  36. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/cli.py +0 -0
  37. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/conversation_scope.py +0 -0
  38. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/domains.py +0 -0
  39. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/hierarchy.py +0 -0
  40. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/mcp_results.py +0 -0
  41. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/migrate.py +0 -0
  42. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/operation_facts.py +0 -0
  43. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/ownership.py +0 -0
  44. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/packaging.py +0 -0
  45. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/signing.py +0 -0
  46. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/src/nutria_plugin/skills.py +0 -0
  47. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/__init__.py +0 -0
  48. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_bundle.py +0 -0
  49. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_capability_contracts.py +0 -0
  50. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_cli.py +0 -0
  51. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_contract_vnext.py +0 -0
  52. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_conversation_scope.py +0 -0
  53. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_hierarchy.py +0 -0
  54. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_manifest.py +0 -0
  55. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_mcp_results.py +0 -0
  56. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_ownership.py +0 -0
  57. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_packaging.py +0 -0
  58. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_prepared_preview.py +0 -0
  59. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_reviewable_actions.py +0 -0
  60. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_signing.py +0 -0
  61. {nutria_plugin-0.7.0 → nutria_plugin-0.8.0}/tests/test_skill_format_docs.py +0 -0
@@ -1,5 +1,44 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0
4
+
5
+ Breaking for manifests that relied on the older, looser audience rules; additive for receipt-aware plugins.
6
+
7
+ - Model the prepared-preview receipt. `PluginReceipt` describes the top-level `receipt` object;
8
+ `HOST_CONTROL_RECEIPT_FIELDS` maps `prepared_action.state_fingerprint` and
9
+ `prepared_action.normalized_effect_fingerprint` to `state_fingerprint` and
10
+ `normalized_effect_fingerprint`; `required_receipt_fields` reads both per-argument
11
+ `x-nutria-host-control` markers and projected `metadata.host_control_bindings`.
12
+ - Add `check_receipt_bindings` and `assert_receipt_bindings`; the latter raises `ReceiptBindingError`
13
+ naming every missing or empty field. Add `RECEIPT_CONFORMANCE_VECTORS` next to the existing preview
14
+ vectors.
15
+ - Add `assert_server_receipt_bindings`/`host_controlled_tools` for plugin tests over every tool whose
16
+ schema declares a host-control marker, and dependency-free `assert_host_preserves_receipt` for Host
17
+ adapter tests.
18
+ - Enforce the closed audience vocabulary (`public_customer`, `private_internal`, `team_internal`).
19
+ Unknown audience values now fail validation.
20
+ - Treat `personal_identifier` as a private output class, like the Host. A `public_customer` capability
21
+ returning `personal_identifier`, `personal_content`, or `special_category` must scope an input to the
22
+ conversation contact.
23
+ - Require the `public_customer` audience when an input declares `scope: "conversation_contact"`.
24
+ - `__version__` now comes from package metadata (or the adjacent `pyproject.toml` in a source
25
+ checkout), with a test that it equals the project version.
26
+ - Remove unused `PreparationToolContract` and `normalize_capability_map`.
27
+
28
+ ### Migration notes
29
+
30
+ - A `public_customer` capability that returns `personal_identifier` without a conversation-scoped input
31
+ is now rejected. Either scope the contact input or drop `public_customer` from its audience. MRW
32
+ `mrw.shipments.status` is one such capability in 0.8.9-beta.
33
+ - A capability that declares `scope: "conversation_contact"` must also declare `public_customer`;
34
+ internal-only capabilities cannot use the scope.
35
+ - Replace any audience value outside the three-name vocabulary; `everyone` and similar values are
36
+ invalid.
37
+ - Plugins importing `PreparationToolContract` or calling `normalize_capability_map` must remove those
38
+ references; both were unused and are gone.
39
+ - A plugin that had pinned `nutria-plugin>=0.6.1` inherits these stricter rules on upgrade; validate
40
+ before publishing.
41
+
3
42
  ## 0.7.0
4
43
 
5
44
  Additive; manifests that do not use the new field are unchanged.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: nutria-plugin
3
- Version: 0.7.0
3
+ Version: 0.8.0
4
4
  Summary: SDK for building, validating, signing, and packaging Nutria plugins
5
5
  Project-URL: Homepage, https://github.com/AlRos14/nutria-plugin-sdk
6
6
  Project-URL: Repository, https://github.com/AlRos14/nutria-plugin-sdk
@@ -22,7 +22,7 @@ Description-Content-Type: text/markdown
22
22
 
23
23
  SDK for building, validating, signing, and packaging Nutria plugins.
24
24
 
25
- Release `0.6.2` accepts only manifest schema `6.0`. Capabilities use their real
25
+ Release `0.8.0` accepts only manifest schema `6.0`. Capabilities use their real
26
26
  business effect (`read`, `write`, or `external_write`); preparation is expressed
27
27
  by producing `prepared_action`, not by a workflow-phase effect. Every parsed
28
28
  requirement resolves `task_context` to `required`, `optional`, or `forbidden`,
@@ -35,7 +35,7 @@ and exact delivery of an approved snapshot.
35
35
  ## Install
36
36
 
37
37
  ```bash
38
- uv add nutria-plugin==0.6.2
38
+ uv add nutria-plugin==0.8.0
39
39
  ```
40
40
 
41
41
  ## Scaffold and validate
@@ -2,7 +2,7 @@
2
2
 
3
3
  SDK for building, validating, signing, and packaging Nutria plugins.
4
4
 
5
- Release `0.6.2` accepts only manifest schema `6.0`. Capabilities use their real
5
+ Release `0.8.0` accepts only manifest schema `6.0`. Capabilities use their real
6
6
  business effect (`read`, `write`, or `external_write`); preparation is expressed
7
7
  by producing `prepared_action`, not by a workflow-phase effect. Every parsed
8
8
  requirement resolves `task_context` to `required`, `optional`, or `forbidden`,
@@ -15,7 +15,7 @@ and exact delivery of an approved snapshot.
15
15
  ## Install
16
16
 
17
17
  ```bash
18
- uv add nutria-plugin==0.6.2
18
+ uv add nutria-plugin==0.8.0
19
19
  ```
20
20
 
21
21
  ## Scaffold and validate
@@ -103,6 +103,8 @@ implementation.
103
103
 
104
104
  Schema extension keys the host understands on a tool argument: `x-nutria-host-control` (the host
105
105
  supplies the value, for example a state fingerprint). Anything else under `x-nutria-` is host-private.
106
+ A tool with a host-control argument must also return the matching fingerprint in its preview's
107
+ top-level `receipt`; see `reviewable-actions.md` and `assert_receipt_bindings`.
106
108
 
107
109
  ## 6. Hierarchical attribute operations
108
110
 
@@ -1,6 +1,6 @@
1
1
  # nutria-plugin SDK documentation
2
2
 
3
- Developer reference for SDK `0.7.0` and manifest schema `6.0`.
3
+ Developer reference for SDK `0.8.0` and manifest schema `6.0`.
4
4
 
5
5
  | Document | Purpose |
6
6
  |---|---|
@@ -1,7 +1,7 @@
1
1
  # plugin.json manifest reference
2
2
 
3
3
  `plugin.json` is the single source of truth for plugin identity, runtime,
4
- capability authority, prepared-action provider defaults, and provider topology. SDK 0.6.2 accepts exactly schema
4
+ capability authority, prepared-action provider defaults, and provider topology. SDK 0.8.0 accepts exactly schema
5
5
  `6.0`; older schemas and unknown fields fail validation.
6
6
 
7
7
  ## Required top-level fields
@@ -3,13 +3,22 @@
3
3
  An agent that answers a person outside the company works in a `public_customer` turn. A capability is offered to that
4
4
  audience only if its manifest says so (`requirements.audience` contains `public_customer`). Most capabilities are not.
5
5
 
6
+ ## Audience vocabulary
7
+
8
+ `requirements.audience` accepts exactly `public_customer`, `private_internal`, and `team_internal`. The SDK rejects any
9
+ other value; the Host uses the same closed vocabulary.
10
+
6
11
  ## The rule
7
12
 
8
13
  A capability offered to `public_customer`:
9
14
 
10
15
  - is a **read** (`effect: read`); writes and sends go through the host's own approval path;
11
16
  - takes **no person-identifying input** (`data_class: personal_identifier`) except the one scoped to the conversation contact;
12
- - if it returns `personal_content` or `special_category` data, **must scope an input to the conversation contact**.
17
+ - if it returns `personal_identifier`, `personal_content`, or `special_category` data, **must scope an input to the
18
+ conversation contact**. Those three classes are private outputs.
19
+
20
+ A capability **not** offered to `public_customer` must not declare `scope: "conversation_contact"`: the scope exists only
21
+ to pin an outside-audience turn.
13
22
 
14
23
  ## Scoping an input
15
24
 
@@ -1,6 +1,6 @@
1
1
  # Python API reference
2
2
 
3
- SDK 0.6.2 exposes the strict schema 6.0 API.
3
+ SDK 0.8.0 exposes the strict schema 6.0 API.
4
4
 
5
5
  ```python
6
6
  from nutria_plugin import (
@@ -11,15 +11,19 @@ from nutria_plugin import (
11
11
  ResourceBinding, ResourceType, ResourceTypeDescriptor,
12
12
  WorldProjectionDescriptor, WorldProviderDescriptor,
13
13
  PreparedActionDescriptor, IdempotencyDescriptor, CompletionDescriptor,
14
- NonCallableReason,
14
+ NonCallableReason, AUDIENCE_VOCABULARY, PRIVATE_OUTPUT_CLASSES,
15
15
  ReviewableActionContract, ReviewableActionField, ReviewableActionMode,
16
- PreparationToolContract,
17
16
  PluginAdminExtension, PluginAdminExtensionKind,
18
17
  PluginAdminExtensionPlacement,
19
18
  PluginAdminFlow, PluginAdminFlowKind, PluginAdminFlowPlacement,
20
19
  PluginBundleError, load_plugin_bundle, extract_plugin_bundle, validate_zip,
21
20
  PackagingError, scaffold_plugin, pack_plugin, validate_plugin_dir,
22
21
  SignatureStatus, generate_keypair, sign_manifest, verify_manifest,
22
+ PluginReceipt, ReceiptBindingError, HOST_CONTROL_RECEIPT_FIELDS,
23
+ RECEIPT_CONFORMANCE_VECTORS, required_receipt_fields,
24
+ check_receipt_bindings, assert_receipt_bindings,
25
+ assert_server_receipt_bindings, host_controlled_tools,
26
+ assert_host_preserves_receipt,
23
27
  )
24
28
  ```
25
29
 
@@ -87,3 +91,22 @@ arguments = apply_conversation_scope(capability, {"chat": "whatever the model se
87
91
 
88
92
  For a capability offered to `public_customer`, the argument declared with `scope: "conversation_contact"` is replaced by the
89
93
  conversation contact. See `outside-audience.md`.
94
+
95
+ ## Preview receipts
96
+
97
+ ```python
98
+ from nutria_plugin import (
99
+ PluginReceipt, ReceiptBindingError,
100
+ assert_receipt_bindings, assert_server_receipt_bindings,
101
+ assert_host_preserves_receipt,
102
+ )
103
+
104
+ receipt = PluginReceipt.model_validate(preview["receipt"])
105
+ assert_receipt_bindings(tool_input_schema, preview)
106
+ checked = assert_server_receipt_bindings(server_tools, {"create_shipment": preview})
107
+ assert_host_preserves_receipt(host_tool_result, preview, input_schema=tool_input_schema)
108
+ ```
109
+
110
+ A tool argument marked `x-nutria-host-control` binds a top-level `receipt` field. The shared
111
+ `RECEIPT_CONFORMANCE_VECTORS` cover a populated receipt, a missing receipt, and empty fields. See
112
+ `reviewable-actions.md`.
@@ -3,7 +3,7 @@
3
3
  ## Install and scaffold
4
4
 
5
5
  ```bash
6
- uv add nutria-plugin==0.6.2
6
+ uv add nutria-plugin==0.8.0
7
7
  nutria-plugin new inventory-lookup --name "Inventory Lookup"
8
8
  ```
9
9
 
@@ -1,6 +1,6 @@
1
1
  # Reviewable actions and external writes
2
2
 
3
- SDK 0.6.0 schema 6.0 defines one reviewable-action architecture:
3
+ SDK 0.8.0 schema 6.0 defines one reviewable-action architecture:
4
4
 
5
5
  ```text
6
6
  ChatBotNutralia -> task context, encrypted draft, revision, approval, idempotency, receipts
@@ -36,9 +36,9 @@ requirements, input bindings, and `reviewable_action_id`:
36
36
  },
37
37
  "reviewable_action_id": "whatsapp-text",
38
38
  "inputs": [
39
- {"kind": "value", "semantic_field": "recipient", "argument_name": "recipient", "sensitivity": "personal", "requires_provenance": true, "accepted_origins": ["current_user", "world_resource"]},
40
- {"kind": "value", "semantic_field": "body", "argument_name": "body", "sensitivity": "personal", "accepted_origins": ["current_user"]},
41
- {"kind": "value", "semantic_field": "idempotency_key", "argument_name": "idempotency_key", "sensitivity": "safe", "accepted_origins": ["current_user"]}
39
+ {"kind": "value", "semantic_field": "recipient", "argument_name": "recipient", "data_class": "personal_identifier", "accepted_origins": ["current_user", "world_resource"]},
40
+ {"kind": "value", "semantic_field": "body", "argument_name": "body", "data_class": "personal_content", "accepted_origins": ["current_user"]},
41
+ {"kind": "value", "semantic_field": "idempotency_key", "argument_name": "idempotency_key", "data_class": "non_personal", "accepted_origins": ["current_user"]}
42
42
  ]
43
43
  }
44
44
  ```
@@ -76,6 +76,47 @@ recipient/thread/source fingerprints, or `write` when it mutates local durable
76
76
  state. The action's `prepare_capability` and `execute_capability` must be
77
77
  distinct and use the same connection.
78
78
 
79
+ ## Preview receipts and host-control bindings
80
+
81
+ A preparation tool whose input schema marks an argument with `x-nutria-host-control` must return
82
+ the matching fingerprint in the preview's **top-level `receipt` object**:
83
+
84
+ | Schema marker | Receipt field |
85
+ |---|---|
86
+ | `prepared_action.state_fingerprint` | `state_fingerprint` |
87
+ | `prepared_action.normalized_effect_fingerprint` | `normalized_effect_fingerprint` |
88
+
89
+ The Host projects the same markers into `metadata.host_control_bindings` and refuses a preview
90
+ that omits or blanks a bound field. `nutria_plugin.PluginReceipt` models the object; the Host may
91
+ add its own fields (`policy_set_fingerprint`, `review_state`), so unknown keys are preserved.
92
+
93
+ `nutria_plugin.assert_receipt_bindings(input_schema, preview_result)` raises
94
+ `ReceiptBindingError` naming every missing or empty field. `check_receipt_bindings` returns the
95
+ same findings as stable `missing_receipt_field:<field>` / `empty_receipt_field:<field>` codes.
96
+ `RECEIPT_CONFORMANCE_VECTORS` are shared positive and negative cases for plugin tests and hosts.
97
+
98
+ A plugin test can check every tool of its MCP server without importing the SDK's MCP stack:
99
+
100
+ ```python
101
+ from nutria_plugin import assert_server_receipt_bindings
102
+
103
+ tools = mcp._tool_manager.list_tools() # or any objects with name + parameters/inputSchema
104
+ previews = {"create_shipment": await create_shipment(..., preview_only=True)}
105
+ checked = assert_server_receipt_bindings(tools, previews)
106
+ ```
107
+
108
+ Only tools whose schema declares a host-control marker are checked; a host-controlled tool with
109
+ no supplied preview is an error. A Host test can prove its adapter still carries the receipt:
110
+
111
+ ```python
112
+ from nutria_plugin import assert_host_preserves_receipt
113
+
114
+ assert_host_preserves_receipt(host_tool_result, provider_preview, input_schema=tool_schema)
115
+ ```
116
+
117
+ The helper is dependency-free: it accepts the Host's `ToolResult` shape (a `receipt` attribute or
118
+ a `data` mapping) and fails when a bound field was dropped, blanked, or changed.
119
+
79
120
  ## Host lifecycle
80
121
 
81
122
  The host exposes generic prepare, inspect, revise, and send operations. A
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "nutria-plugin"
7
- version = "0.7.0"
7
+ version = "0.8.0"
8
8
  description = "SDK for building, validating, signing, and packaging Nutria plugins"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -15,9 +15,13 @@ Signing:
15
15
  generate_keypair, sign_manifest, verify_manifest, SignatureStatus
16
16
  """
17
17
 
18
- __version__ = "0.6.3"
18
+ import tomllib
19
+ from importlib.metadata import PackageNotFoundError, version as _distribution_version
20
+ from pathlib import Path
19
21
 
20
22
  from .capabilities import (
23
+ AUDIENCE_VOCABULARY,
24
+ PRIVATE_OUTPUT_CLASSES,
21
25
  CapabilityDescriptor,
22
26
  CapabilityEffect,
23
27
  CapabilityExposure,
@@ -50,8 +54,19 @@ from .ownership import (
50
54
  ownership_from_event_payload,
51
55
  )
52
56
  from .prepared_preview import (
57
+ HOST_CONTROL_RECEIPT_FIELDS,
53
58
  PREVIEW_CONFORMANCE_VECTORS,
59
+ RECEIPT_CONFORMANCE_VECTORS,
60
+ PluginReceipt,
61
+ ReceiptBindingError,
62
+ assert_host_preserves_receipt,
63
+ assert_receipt_bindings,
64
+ assert_server_receipt_bindings,
54
65
  check_prepared_preview,
66
+ check_receipt_bindings,
67
+ host_controlled_tools,
68
+ receipt_field_for_control,
69
+ required_receipt_fields,
55
70
  )
56
71
  from .domains import CapabilityDomain, CAPABILITY_DOMAIN_IDS, DOMAIN_LABELS
57
72
  from .hierarchy import (
@@ -73,7 +88,6 @@ from .manifest import (
73
88
  PluginAdminFlowPlacement,
74
89
  PluginManifest,
75
90
  PluginPaths,
76
- PreparationToolContract,
77
91
  ReviewableActionContract,
78
92
  ReviewableActionField,
79
93
  ReviewableActionMode,
@@ -94,6 +108,37 @@ from .mcp_results import (
94
108
  from .operation_facts import OPERATION_FACTS_KEY, OperationFacts, TargetFact, extract_operation_facts
95
109
  from .skills import SkillFrontmatter, parse_skill_frontmatter
96
110
 
111
+ _FALLBACK_VERSION = "0.8.0"
112
+
113
+
114
+ def _source_checkout_version() -> str | None:
115
+ """Read the adjacent pyproject.toml when this module is imported from a source tree."""
116
+ pyproject = Path(__file__).resolve().parents[2] / "pyproject.toml"
117
+ if not pyproject.is_file():
118
+ return None
119
+ try:
120
+ project = tomllib.loads(pyproject.read_text(encoding="utf-8")).get("project") or {}
121
+ except (OSError, ValueError, tomllib.TOMLDecodeError):
122
+ return None
123
+ value = str(project.get("version") or "").strip()
124
+ return value or None
125
+
126
+
127
+ def _distribution_version_fallback() -> str:
128
+ try:
129
+ return _distribution_version("nutria-plugin")
130
+ except PackageNotFoundError:
131
+ return _FALLBACK_VERSION
132
+
133
+
134
+ def _resolve_version() -> str:
135
+ # A source checkout is authoritative: an unrelated installed distribution (for example a
136
+ # host venv's older SDK) must not make this tree report a different version.
137
+ return _source_checkout_version() or _distribution_version_fallback()
138
+
139
+
140
+ __version__ = _resolve_version()
141
+
97
142
  __all__ = [
98
143
  "__version__",
99
144
  # Conversation scope for outside audiences
@@ -123,7 +168,8 @@ __all__ = [
123
168
  "ReviewableActionContract",
124
169
  "ReviewableActionMode",
125
170
  "ReviewableActionField",
126
- "PreparationToolContract",
171
+ "AUDIENCE_VOCABULARY",
172
+ "PRIVATE_OUTPUT_CLASSES",
127
173
  "CapabilityDescriptor",
128
174
  "CapabilityEffect",
129
175
  "CapabilityExposure",
@@ -167,7 +213,18 @@ __all__ = [
167
213
  "MCPResultContractError",
168
214
  # Prepared-preview conformance
169
215
  "PREVIEW_CONFORMANCE_VECTORS",
216
+ "RECEIPT_CONFORMANCE_VECTORS",
217
+ "HOST_CONTROL_RECEIPT_FIELDS",
218
+ "PluginReceipt",
219
+ "ReceiptBindingError",
220
+ "receipt_field_for_control",
221
+ "required_receipt_fields",
170
222
  "check_prepared_preview",
223
+ "check_receipt_bindings",
224
+ "assert_receipt_bindings",
225
+ "assert_server_receipt_bindings",
226
+ "host_controlled_tools",
227
+ "assert_host_preserves_receipt",
171
228
  "normalize_mcp_result",
172
229
  "project_result_path",
173
230
  "validate_capability_result",
@@ -13,6 +13,9 @@ from .hierarchy import HierarchicalAttributeDescriptor
13
13
 
14
14
  _RESOURCE_TYPE_PATTERN = r"^[a-z][a-z0-9_.-]{0,127}$"
15
15
 
16
+ #: The audience vocabulary shared with the Host. Unknown values fail validation.
17
+ AUDIENCE_VOCABULARY = frozenset({"public_customer", "private_internal", "team_internal"})
18
+
16
19
 
17
20
  class CapabilityEffect(str, Enum):
18
21
  READ = "read"
@@ -44,6 +47,12 @@ class DataClass(str, Enum):
44
47
  SPECIAL_CATEGORY = "special_category"
45
48
 
46
49
 
50
+ #: Output classes the Host treats as private for an outside audience.
51
+ PRIVATE_OUTPUT_CLASSES = frozenset(
52
+ {DataClass.PERSONAL_IDENTIFIER, DataClass.PERSONAL_CONTENT, DataClass.SPECIAL_CATEGORY}
53
+ )
54
+
55
+
47
56
  class CapabilityExposure(str, Enum):
48
57
  """Who may invoke a graph-visible capability."""
49
58
 
@@ -182,7 +191,16 @@ class CapabilityRequirement(BaseModel):
182
191
  @field_validator("audience")
183
192
  @classmethod
184
193
  def _validate_audience(cls, value: list[str]) -> list[str]:
185
- return list(dict.fromkeys(item.strip() for item in value if item.strip()))
194
+ cleaned = list(dict.fromkeys(item.strip() for item in value if item.strip()))
195
+ unknown = sorted(set(cleaned) - AUDIENCE_VOCABULARY)
196
+ if unknown:
197
+ raise ValueError(
198
+ "capability audience must use "
199
+ + ", ".join(sorted(AUDIENCE_VOCABULARY))
200
+ + "; unknown: "
201
+ + ", ".join(unknown)
202
+ )
203
+ return cleaned
186
204
 
187
205
 
188
206
  class ResourceBinding(BaseModel):
@@ -419,6 +437,10 @@ class CapabilityDescriptor(BaseModel):
419
437
  raise ValueError("a capability may scope only one input to the conversation contact")
420
438
  if scoped and self.effect != CapabilityEffect.READ:
421
439
  raise ValueError("only read capabilities may scope an input to the conversation contact")
440
+ if scoped and "public_customer" not in self.requirements.audience:
441
+ raise ValueError(
442
+ "a conversation-scoped input requires the public_customer audience"
443
+ )
422
444
  if "public_customer" in self.requirements.audience:
423
445
  if self.effect != CapabilityEffect.READ:
424
446
  raise ValueError("only read capabilities may be offered to the public_customer audience")
@@ -433,12 +455,11 @@ class CapabilityDescriptor(BaseModel):
433
455
  "scope it to the conversation contact"
434
456
  )
435
457
  if not scoped and any(
436
- out.data_class in {DataClass.PERSONAL_CONTENT, DataClass.SPECIAL_CATEGORY}
437
- for out in self.produces
458
+ out.data_class in PRIVATE_OUTPUT_CLASSES for out in self.produces
438
459
  ):
439
460
  raise ValueError(
440
- "a public_customer capability that returns personal content must scope an input "
441
- "to the conversation contact"
461
+ "a public_customer capability that returns personal or identifying content "
462
+ "must scope an input to the conversation contact"
442
463
  )
443
464
  output_names = [item.output_name for item in self.produces]
444
465
  if len(output_names) != len(set(output_names)):
@@ -483,10 +504,3 @@ class CapabilityDescriptor(BaseModel):
483
504
  if not self.inputs:
484
505
  raise ValueError("model-selectable writes require declared inputs")
485
506
  return self
486
-
487
-
488
- def normalize_capability_map(value: Any) -> list[CapabilityDescriptor]:
489
- """Parse a manifest capability list with a useful validation error."""
490
- if not isinstance(value, list):
491
- raise ValueError("capabilities must be a list of capability descriptors")
492
- return [CapabilityDescriptor.model_validate(item) for item in value]
@@ -93,26 +93,6 @@ class ReviewableActionField(str, Enum):
93
93
  MODE = "mode"
94
94
 
95
95
 
96
- class PreparationToolContract(BaseModel):
97
- """Optional pure adapter used to resolve a reply envelope.
98
-
99
- Preparation may read a connector and return structured provenance, but it
100
- can never persist a draft or perform an external write.
101
- """
102
-
103
- name: str = Field(..., pattern=r"^[a-zA-Z][a-zA-Z0-9_-]{0,127}$")
104
- external_write: bool = False
105
- side_effect: str = Field(default="read", pattern=r"^(read|pure|none)$")
106
-
107
- model_config = {"extra": "forbid"}
108
-
109
- @model_validator(mode="after")
110
- def _must_be_pure(self) -> "PreparationToolContract":
111
- if self.external_write:
112
- raise ValueError("preparation tools must be pure/read-only and cannot write externally")
113
- return self
114
-
115
-
116
96
  class ReviewableActionContract(BaseModel):
117
97
  """Contract between ChatBotNutralia's draft store and a plugin delivery tool."""
118
98