mesa-core 1.0.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 (73) hide show
  1. mesa_core-1.0.0/.claude/settings.local.json +14 -0
  2. mesa_core-1.0.0/.github/workflows/ci.yml +27 -0
  3. mesa_core-1.0.0/.gitignore +13 -0
  4. mesa_core-1.0.0/CLAUDE.md +61 -0
  5. mesa_core-1.0.0/CONTRIBUTING.md +52 -0
  6. mesa_core-1.0.0/LICENSE +196 -0
  7. mesa_core-1.0.0/PKG-INFO +143 -0
  8. mesa_core-1.0.0/README.md +109 -0
  9. mesa_core-1.0.0/SECURITY.md +49 -0
  10. mesa_core-1.0.0/documents/MESA-Enrichment.md +511 -0
  11. mesa_core-1.0.0/documents/MESA-Getting-Started.md +1158 -0
  12. mesa_core-1.0.0/documents/MESA-Module.md +1051 -0
  13. mesa_core-1.0.0/documents/MESA-Overview.md +189 -0
  14. mesa_core-1.0.0/documents/MESA-Specification.md +1292 -0
  15. mesa_core-1.0.0/documents/benchmark.md +90 -0
  16. mesa_core-1.0.0/memory/MEMORY.md +3 -0
  17. mesa_core-1.0.0/memory/update-docs-after-changes.md +12 -0
  18. mesa_core-1.0.0/mesa_core/__init__.py +76 -0
  19. mesa_core-1.0.0/mesa_core/backends/__init__.py +29 -0
  20. mesa_core-1.0.0/mesa_core/backends/jsonfile.py +43 -0
  21. mesa_core-1.0.0/mesa_core/backends/memory.py +29 -0
  22. mesa_core-1.0.0/mesa_core/backends/sqlite.py +57 -0
  23. mesa_core-1.0.0/mesa_core/conflict.py +595 -0
  24. mesa_core-1.0.0/mesa_core/enforcer.py +431 -0
  25. mesa_core-1.0.0/mesa_core/exceptions.py +34 -0
  26. mesa_core-1.0.0/mesa_core/inheritance.py +202 -0
  27. mesa_core-1.0.0/mesa_core/integration_import.py +51 -0
  28. mesa_core-1.0.0/mesa_core/mcp/__init__.py +5 -0
  29. mesa_core-1.0.0/mesa_core/mcp/adapters/__init__.py +39 -0
  30. mesa_core-1.0.0/mesa_core/mcp/adapters/fastmcp.py +47 -0
  31. mesa_core-1.0.0/mesa_core/mcp/adapters/raw_sdk.py +63 -0
  32. mesa_core-1.0.0/mesa_core/mcp/schemas.py +83 -0
  33. mesa_core-1.0.0/mesa_core/mcp/tools.py +244 -0
  34. mesa_core-1.0.0/mesa_core/migration.py +57 -0
  35. mesa_core-1.0.0/mesa_core/privacy.py +135 -0
  36. mesa_core-1.0.0/mesa_core/profile.py +444 -0
  37. mesa_core-1.0.0/mesa_core/py.typed +0 -0
  38. mesa_core-1.0.0/mesa_core/schemas/mesa_profile.schema.json +485 -0
  39. mesa_core-1.0.0/mesa_core/schemas/mesa_tools.schema.json +117 -0
  40. mesa_core-1.0.0/mesa_core/store.py +426 -0
  41. mesa_core-1.0.0/mesa_core/temporal.py +147 -0
  42. mesa_core-1.0.0/mesa_core/trigger_validator.py +142 -0
  43. mesa_core-1.0.0/mesa_core/validation.py +238 -0
  44. mesa_core-1.0.0/mesa_core/vocabulary.py +170 -0
  45. mesa_core-1.0.0/pyproject.toml +62 -0
  46. mesa_core-1.0.0/tests/__init__.py +0 -0
  47. mesa_core-1.0.0/tests/conformance/__init__.py +0 -0
  48. mesa_core-1.0.0/tests/conformance/malformed/invalid_control_mode.json +14 -0
  49. mesa_core-1.0.0/tests/conformance/malformed/invalid_operator.json +30 -0
  50. mesa_core-1.0.0/tests/conformance/malformed/missing_confidence.json +17 -0
  51. mesa_core-1.0.0/tests/conformance/malformed/missing_generated_at.json +17 -0
  52. mesa_core-1.0.0/tests/conformance/malformed/trust_laundering.json +18 -0
  53. mesa_core-1.0.0/tests/conformance/test_conflict.py +496 -0
  54. mesa_core-1.0.0/tests/conformance/test_control_mode.py +419 -0
  55. mesa_core-1.0.0/tests/conformance/test_inferred.py +126 -0
  56. mesa_core-1.0.0/tests/conformance/test_inheritance.py +305 -0
  57. mesa_core-1.0.0/tests/conformance/test_kernel.py +246 -0
  58. mesa_core-1.0.0/tests/conformance/test_privacy.py +112 -0
  59. mesa_core-1.0.0/tests/conformance/test_temporal.py +180 -0
  60. mesa_core-1.0.0/tests/conformance/test_trigger_validator.py +103 -0
  61. mesa_core-1.0.0/tests/fixtures/profiles/helper_mode_flag.json +23 -0
  62. mesa_core-1.0.0/tests/fixtures/profiles/inferred_valid.json +18 -0
  63. mesa_core-1.0.0/tests/fixtures/profiles/light_kernel.json +16 -0
  64. mesa_core-1.0.0/tests/fixtures/profiles/lock_full.json +33 -0
  65. mesa_core-1.0.0/tests/fixtures/profiles/vacuum_negate_temporal.json +24 -0
  66. mesa_core-1.0.0/tests/integration/__init__.py +0 -0
  67. mesa_core-1.0.0/tests/integration/test_fastmcp_adapter.py +23 -0
  68. mesa_core-1.0.0/tests/integration/test_raw_sdk_adapter.py +27 -0
  69. mesa_core-1.0.0/tests/test_integration_import.py +86 -0
  70. mesa_core-1.0.0/tests/test_mcp_tools.py +241 -0
  71. mesa_core-1.0.0/tests/test_migration.py +47 -0
  72. mesa_core-1.0.0/tests/test_store.py +267 -0
  73. mesa_core-1.0.0/tests/test_validation_schema_agreement.py +53 -0
@@ -0,0 +1,14 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(curl -s -o /dev/null -w \"%{http_code}\" https://pypi.org/pypi/mesa-core/json)",
5
+ "Bash(curl -s https://pypi.org/simple/mesa-core/ -H \"Accept: application/vnd.pypi.simple.v1+json\" -o /dev/null -w \"%{http_code}\")",
6
+ "Bash(curl -s https://raw.githubusercontent.com/home-assistant/core/dev/script/hassfest/manifest.py)",
7
+ "Bash(python3 -m venv .venv)",
8
+ "Bash(.venv/bin/pip -q install -e \".[dev]\")",
9
+ "Bash(.venv/bin/ruff check *)",
10
+ "Bash(.venv/bin/mypy)",
11
+ "Bash(.venv/bin/pytest tests/ -q)"
12
+ ]
13
+ }
14
+ }
@@ -0,0 +1,27 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ python-version: ["3.11", "3.12", "3.13", "3.14"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - name: Install
21
+ run: pip install -e ".[dev,fastmcp,mcp]"
22
+ - name: Lint
23
+ run: ruff check .
24
+ - name: Type check
25
+ run: mypy
26
+ - name: Test
27
+ run: pytest tests/ -v
@@ -0,0 +1,13 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .venv/
7
+ .mypy_cache/
8
+ .ruff_cache/
9
+ .pytest_cache/
10
+ .DS_Store
11
+
12
+ # Internal-only developer notes (not for publication)
13
+ AUDIT-NOTES.md
@@ -0,0 +1,61 @@
1
+ ## 1. Think Before Coding
2
+
3
+ **Don't assume. Don't hide confusion. Surface tradeoffs.**
4
+
5
+ Before implementing:
6
+ - State your assumptions explicitly. If uncertain, ask.
7
+ - If multiple interpretations exist, present them - don't pick silently.
8
+ - If a simpler approach exists, say so. Push back when warranted.
9
+ - If something is unclear, stop. Name what's confusing. Ask.
10
+
11
+ ## 2. Simplicity First
12
+
13
+ **Minimum code that solves the problem. Nothing speculative.**
14
+
15
+ - No features beyond what was asked.
16
+ - No abstractions for single-use code.
17
+ - No "flexibility" or "configurability" that wasn't requested.
18
+ - No error handling for impossible scenarios.
19
+ - If you write 200 lines and it could be 50, rewrite it.
20
+
21
+ Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
22
+
23
+ ## 3. Surgical Changes
24
+
25
+ **Touch only what you must. Clean up only your own mess.**
26
+
27
+ When editing existing code:
28
+ - Don't "improve" adjacent code, comments, or formatting.
29
+ - Don't refactor things that aren't broken.
30
+ - Match existing style, even if you'd do it differently.
31
+ - If you notice unrelated dead code, mention it - and await instructions.
32
+
33
+ When your changes create orphans:
34
+ - Remove imports/variables/functions that YOUR changes made unused.
35
+ - Don't remove pre-existing dead code unless asked.
36
+ - Always mention orphans, and await instructions.
37
+
38
+ The test: Every changed line should trace directly to the user's request.
39
+
40
+ ## 4. Goal-Driven Execution
41
+
42
+ **Define success criteria. Loop until verified.**
43
+
44
+ Transform tasks into verifiable goals:
45
+ - "Add validation" → "Write tests for invalid inputs, then make them pass"
46
+ - "Fix the bug" → "Write a test that reproduces it, then make it pass"
47
+ - "Refactor X" → "Ensure tests pass before and after"
48
+
49
+ For multi-step tasks, state a brief plan:
50
+ ```
51
+ 1. [Step] → verify: [check]
52
+ 2. [Step] → verify: [check]
53
+ 3. [Step] → verify: [check]
54
+ ```
55
+
56
+ **Style and formatting:**
57
+ - Never use em dashes (—) or en dashes (–) anywhere. Use commas, periods, hyphens, or semicolons instead.
58
+ - Never use ASCII arrows (→) unless the character is specifically required by a protocol or format.
59
+ - No emojis anywhere in source code, comments, or documentation, unless it is needed for UI output.
60
+ - No forced line breaks in prose paragraphs in Markdown files.
61
+
@@ -0,0 +1,52 @@
1
+ # Contributing to mesa-core
2
+
3
+ Thanks for your interest in mesa-core. This is a short read, because the project has one rule that is easy to miss and shapes everything else.
4
+
5
+ ## mesa-core is a reference implementation, not a standalone library
6
+
7
+ mesa-core implements the MESA Specification. As the spec states (Section 23, "Reference implementation"), when the specification and mesa-core behaviour diverge, the specification takes precedence. That changes what a contribution means here:
8
+
9
+ - An implementation bug is code that does not match what the spec says. Fixing it is always welcome; open a pull request.
10
+
11
+ - A behaviour or semantics change is a change to what the spec says should happen: anything that alters the effective profile a given input produces. These need a spec discussion first. Open an issue that cites the relevant spec section before sending a PR, so the spec and the implementation move together rather than drifting apart.
12
+
13
+ If you are unsure which category your change falls into, open an issue and ask. That is never the wrong move.
14
+
15
+ ## Reporting a spec/implementation divergence
16
+
17
+ If you find a place where mesa-core does something the spec does not describe, or contradicts it, that is a bug report worth filing on its own. Open a GitHub issue with the spec section, the observed behaviour, and a minimal profile that reproduces it.
18
+
19
+ ## Development setup
20
+
21
+ The README has the canonical setup. In short:
22
+
23
+ ```bash
24
+ git clone https://github.com/sfox38/mesa-core
25
+ cd mesa-core
26
+ pip install -e ".[dev]"
27
+ ```
28
+
29
+ CI runs three gates on every push and pull request, across Python 3.11 through 3.14. Run them locally before you push:
30
+
31
+ ```bash
32
+ ruff check . # lint and import order
33
+ mypy # strict type checking
34
+ pytest tests/ -v # conformance suite
35
+ ```
36
+
37
+ A change that touches resolution, enforcement, or validation should come with a conformance test under `tests/conformance/` that pins the behaviour, in the style of the existing tests.
38
+
39
+ ## Code style
40
+
41
+ mesa-core favours small, surgical changes that match the surrounding code.
42
+
43
+ - Keep changes minimal and traceable to a stated goal. Prefer the simplest code that solves the problem.
44
+ - Safety logic is fail-closed: an evaluation that cannot be completed must tighten, never loosen. Preserve this property in anything you touch.
45
+
46
+ ## Versioning
47
+
48
+ mesa-core follows the schema versioning in spec Section 23: patch (1.0.x) fixes errors, minor (1.x.0) adds optional fields, and major (x.0.0) may introduce breaking changes with a documented migration path.
49
+
50
+ ## License
51
+
52
+ By contributing, you agree that your contributions are licensed under the Apache License 2.0, the same license as the project.
@@ -0,0 +1,196 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as defined in Section 5, any work of
48
+ authorship, including the original version of the Work and any
49
+ modifications or additions to that Work or Derivative Works of the
50
+ Work, that is intentionally submitted to the Licensor for inclusion
51
+ in the Work by the copyright owner or by an individual or Legal Entity
52
+ authorized to submit on behalf of the copyright owner. For the purposes
53
+ of this definition, "submitted" means any form of electronic, verbal,
54
+ or written communication sent to the Licensor or its representatives,
55
+ including but not limited to communication on electronic mailing lists,
56
+ source code control systems, and issue tracking systems that are managed
57
+ by, or on behalf of, the Licensor for the purpose of discussing and
58
+ improving the Work, but excluding communication that is conspicuously
59
+ marked or designated in writing by the copyright owner as "Not a
60
+ Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
63
+ whom a Contribution has been received by the Licensor and included
64
+ within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, You must include a readable copy of the
108
+ attribution notices contained within such NOTICE file, in
109
+ at least one of the following places: within a NOTICE text
110
+ file distributed as part of the Derivative Works; within
111
+ the Source form or documentation, if provided along with the
112
+ Derivative Works; or, within a display generated by the
113
+ Derivative Works, if and wherever such third-party notices
114
+ normally appear. The contents of the NOTICE file are for
115
+ informational purposes only and do not modify the License.
116
+ You may add Your own attribution notices within Derivative
117
+ Works that You distribute, alongside or as an addendum to
118
+ the NOTICE text from the Work, provided that such additional
119
+ attribution notices cannot be construed as modifying the
120
+ License.
121
+
122
+ You may add Your own license statement for Your modifications and
123
+ may provide additional grant of rights to use, copy, modify, merge,
124
+ publish, distribute, sublicense, and/or sell copies of the Work,
125
+ subject to Your compliance with the terms of this License.
126
+
127
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
128
+ any Contribution intentionally submitted for inclusion in the Work
129
+ by You to the Licensor shall be under the terms and conditions of
130
+ this License, without any additional terms or conditions.
131
+ Notwithstanding the above, nothing herein shall supersede or modify
132
+ the terms of any separate license agreement you may have executed
133
+ with Licensor regarding such Contributions.
134
+
135
+ 6. Trademarks. This License does not grant permission to use the trade
136
+ names, trademarks, service marks, or product names of the Licensor,
137
+ except as required for reasonable and customary use in describing the
138
+ origin of the Work and reproducing the content of the NOTICE file.
139
+
140
+ 7. Disclaimer of Warranty. Unless required by applicable law or
141
+ agreed to in writing, Licensor provides the Work (and each
142
+ Contributor provides its Contributions) on an "AS IS" BASIS,
143
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
144
+ implied, including, without limitation, any warranties or conditions
145
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
146
+ PARTICULAR PURPOSE. You are solely responsible for determining the
147
+ appropriateness of using or reproducing the Work and assume any
148
+ risks associated with Your exercise of permissions under this License.
149
+
150
+ 8. Limitation of Liability. In no event and under no legal theory,
151
+ whether in tort (including negligence), contract, or otherwise,
152
+ unless required by applicable law (such as deliberate and grossly
153
+ negligent acts) or agreed to in writing, shall any Contributor be
154
+ liable to You for damages, including any direct, indirect, special,
155
+ incidental, or exemplary damages of any character arising as a
156
+ result of this License or out of the use or inability to use the
157
+ Work (including but not limited to damages for loss of goodwill,
158
+ work stoppage, computer failure or malfunction, or all other
159
+ commercial damages or losses), even if such Contributor has been
160
+ advised of the possibility of such damages.
161
+
162
+ 9. Accepting Warranty or Additional Liability. While redistributing
163
+ the Work or Derivative Works thereof, You may choose to offer,
164
+ and charge a fee for, acceptance of support, warranty, indemnity,
165
+ or other liability obligations and/or rights consistent with this
166
+ License. However, in accepting such obligations, You may charge a
167
+ fee on behalf to all other Contributors whose liability obligations
168
+ are not expressly stated in the License, but only on behalf of
169
+ parties exercising rights under this License, and only if You
170
+ accept that all such warranty or additional liability is solely
171
+ Your responsibility.
172
+
173
+ END OF TERMS AND CONDITIONS
174
+
175
+ APPENDIX: How to apply the Apache License to your work.
176
+
177
+ To apply the Apache License to your work, attach the following
178
+ boilerplate notice, with the fields enclosed by brackets "[]"
179
+ replaced with your own identifying information. (Don't include
180
+ the brackets!) The text should be enclosed in the appropriate
181
+ comment syntax for the file format in use. An end-line or comment
182
+ delimiter may be needed for some file formats.
183
+
184
+ Copyright 2026 Steven Fox
185
+
186
+ Licensed under the Apache License, Version 2.0 (the "License");
187
+ you may not use this file except in compliance with the License.
188
+ You may obtain a copy of the License at
189
+
190
+ http://www.apache.org/licenses/LICENSE-2.0
191
+
192
+ Unless required by applicable law or agreed to in writing, software
193
+ distributed under the License is distributed on an "AS IS" BASIS,
194
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
195
+ See the License for the specific language governing permissions and
196
+ limitations under the License.
@@ -0,0 +1,143 @@
1
+ Metadata-Version: 2.4
2
+ Name: mesa-core
3
+ Version: 1.0.0
4
+ Summary: Reference implementation of the MESA specification: a semantic safety and coordination layer for AI-operated smart environments.
5
+ Project-URL: Homepage, https://github.com/sfox38/mesa-core
6
+ Project-URL: Documentation, https://github.com/sfox38/mesa-core/tree/main/documents
7
+ Author-email: Steven Fox <sfox38@gmail.com>
8
+ License: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: ai-agents,home-assistant,mcp,semantics,smart-home
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.11
21
+ Provides-Extra: dev
22
+ Requires-Dist: jsonschema>=4; extra == 'dev'
23
+ Requires-Dist: mypy>=1.11; extra == 'dev'
24
+ Requires-Dist: pytest>=8; extra == 'dev'
25
+ Requires-Dist: ruff>=0.6; extra == 'dev'
26
+ Provides-Extra: fastmcp
27
+ Requires-Dist: fastmcp; extra == 'fastmcp'
28
+ Provides-Extra: mcp
29
+ Requires-Dist: mcp; extra == 'mcp'
30
+ Provides-Extra: test
31
+ Requires-Dist: jsonschema>=4; extra == 'test'
32
+ Requires-Dist: pytest>=8; extra == 'test'
33
+ Description-Content-Type: text/markdown
34
+
35
+
36
+ # mesa-core
37
+
38
+ [![CI](https://github.com/sfox38/mesa-core/actions/workflows/ci.yml/badge.svg)](https://github.com/sfox38/mesa-core/actions/workflows/ci.yml)
39
+ [![PyPI](https://img.shields.io/pypi/v/mesa-core.svg)](https://pypi.org/project/mesa-core/)
40
+
41
+ mesa-core decides whether an AI agent should be allowed to act on a smart-home device, and how cautious it should be about it.
42
+
43
+ When an assistant tries to turn on a light, unlock the front door, or change the thermostat, mesa-core answers three questions: is this allowed, should the user confirm it first, and why. It ships with safe defaults (a light is fine to control automatically; unlike a lock) that you refine for each home.
44
+
45
+ It is the reference implementation of the [MESA specification](documents/MESA-Specification.md). It has no runtime dependencies and never talks to Home Assistant directly: you hand it device state through callback functions, and it hands you decisions.
46
+
47
+ ```bash
48
+ pip install mesa-core
49
+ ```
50
+
51
+ ## Quick look
52
+
53
+ ```python
54
+ from mesa_core import MesaEnforcer, ProfileStore
55
+ from mesa_core.backends import MemoryBackend
56
+
57
+ enforcer = MesaEnforcer(ProfileStore(backend=MemoryBackend()))
58
+
59
+ # An AI agent wants to unlock the front door. Should it?
60
+ result = enforcer.evaluate("lock.front_door", "lock.unlock")
61
+
62
+ result.allowed # False
63
+ result.reason # "Entity is prohibited by policy: lock.front_door"
64
+ ```
65
+
66
+ ## How decisions work
67
+
68
+ - Every device has a control mode: act freely, ask the user first, read-only, or never act.
69
+ - Devices you have not configured fall back to safe defaults: lights act freely, locks and alarm panels are off-limits, everything else asks first.
70
+ - Rules can be set for a single device, an area, or a whole device type, and are combined with a bias toward caution: the more restrictive rule wins, and anything that cannot be checked blocks rather than allows.
71
+ - You can add finer limits (cap the speaker volume after 10pm) and time-based rules (no blinds before sunrise).
72
+
73
+ ## Asking the user to confirm
74
+
75
+ When a device is set to confirm first, `evaluate` returns a challenge instead of a yes. Show the action to the user, then call again with the token from the approved challenge.
76
+
77
+ ```python
78
+ result = enforcer.evaluate("cover.garage", "cover.open_cover")
79
+ if result.confirmation_challenge:
80
+ # present result.confirmation_challenge to the user; once approved,
81
+ # build a confirmation_token from it and re-submit the same call:
82
+ result = enforcer.evaluate(
83
+ "cover.garage", "cover.open_cover",
84
+ confirmation_token=approved_token,
85
+ )
86
+ ```
87
+
88
+ ## Reading a device's profile
89
+
90
+ `ProfileStore` resolves the effective profile after inheritance and defaults. Use a file backend to persist profiles under your HA config:
91
+
92
+ ```python
93
+ from mesa_core import ProfileStore
94
+ from mesa_core.backends import JsonFileBackend
95
+
96
+ store = ProfileStore(backend=JsonFileBackend("/config/mesa/"))
97
+ profile = store.get_effective("light.living_room_ceiling")
98
+ profile.operational_boundaries.control_mode # ControlMode.AUTONOMOUS
99
+ ```
100
+
101
+ ## Exposing it to an AI agent (MCP)
102
+
103
+ Register MESA's tools into an MCP server so the agent can look up profiles and caller context for itself.
104
+
105
+ ```python
106
+ from mesa_core.mcp import register_mesa_tools
107
+
108
+ register_mesa_tools(store, adapter="fastmcp", server=app)
109
+ ```
110
+
111
+ Adapters ship for FastMCP and the MCP Python SDK (`pip install "mesa-core[fastmcp]"` or `"mesa-core[mcp]"`). Any other framework can implement a small registration protocol.
112
+
113
+ ## Loading profiles shipped by integrations
114
+
115
+ An HA integration can ship a `mesa_profile.json` describing its own devices. Load it with:
116
+
117
+ ```python
118
+ from mesa_core import import_from_integration
119
+
120
+ profile = import_from_integration("/config/custom_components/my_integration")
121
+ if profile is not None:
122
+ store.set_domain_profile(profile.entity_id, profile)
123
+ ```
124
+
125
+ ## Documentation
126
+
127
+ - [MESA Overview](documents/MESA-Overview.md) - the problem MESA solves, in plain terms
128
+ - [Getting Started](documents/MESA-Getting-Started.md) - write your first profile
129
+ - [Specification](documents/MESA-Specification.md) - the full normative reference
130
+ - [Enrichment](documents/MESA-Enrichment.md) - optional advanced domains
131
+ - [Module Proposal](documents/MESA-Module.md) - how this library is built
132
+
133
+ ## Status
134
+
135
+ mesa-core v1.0 is ready for use: profile storage and inheritance, enforcement with confirmation, the MCP retrieval tools, and privacy controls are all implemented.
136
+
137
+ ```bash
138
+ git clone https://github.com/sfox38/mesa-core
139
+ cd mesa-core
140
+ pip install -e ".[dev]"
141
+ pytest tests/ -v # test suite
142
+ ruff check . && mypy # lint and type check
143
+ ```
@@ -0,0 +1,109 @@
1
+
2
+ # mesa-core
3
+
4
+ [![CI](https://github.com/sfox38/mesa-core/actions/workflows/ci.yml/badge.svg)](https://github.com/sfox38/mesa-core/actions/workflows/ci.yml)
5
+ [![PyPI](https://img.shields.io/pypi/v/mesa-core.svg)](https://pypi.org/project/mesa-core/)
6
+
7
+ mesa-core decides whether an AI agent should be allowed to act on a smart-home device, and how cautious it should be about it.
8
+
9
+ When an assistant tries to turn on a light, unlock the front door, or change the thermostat, mesa-core answers three questions: is this allowed, should the user confirm it first, and why. It ships with safe defaults (a light is fine to control automatically; unlike a lock) that you refine for each home.
10
+
11
+ It is the reference implementation of the [MESA specification](documents/MESA-Specification.md). It has no runtime dependencies and never talks to Home Assistant directly: you hand it device state through callback functions, and it hands you decisions.
12
+
13
+ ```bash
14
+ pip install mesa-core
15
+ ```
16
+
17
+ ## Quick look
18
+
19
+ ```python
20
+ from mesa_core import MesaEnforcer, ProfileStore
21
+ from mesa_core.backends import MemoryBackend
22
+
23
+ enforcer = MesaEnforcer(ProfileStore(backend=MemoryBackend()))
24
+
25
+ # An AI agent wants to unlock the front door. Should it?
26
+ result = enforcer.evaluate("lock.front_door", "lock.unlock")
27
+
28
+ result.allowed # False
29
+ result.reason # "Entity is prohibited by policy: lock.front_door"
30
+ ```
31
+
32
+ ## How decisions work
33
+
34
+ - Every device has a control mode: act freely, ask the user first, read-only, or never act.
35
+ - Devices you have not configured fall back to safe defaults: lights act freely, locks and alarm panels are off-limits, everything else asks first.
36
+ - Rules can be set for a single device, an area, or a whole device type, and are combined with a bias toward caution: the more restrictive rule wins, and anything that cannot be checked blocks rather than allows.
37
+ - You can add finer limits (cap the speaker volume after 10pm) and time-based rules (no blinds before sunrise).
38
+
39
+ ## Asking the user to confirm
40
+
41
+ When a device is set to confirm first, `evaluate` returns a challenge instead of a yes. Show the action to the user, then call again with the token from the approved challenge.
42
+
43
+ ```python
44
+ result = enforcer.evaluate("cover.garage", "cover.open_cover")
45
+ if result.confirmation_challenge:
46
+ # present result.confirmation_challenge to the user; once approved,
47
+ # build a confirmation_token from it and re-submit the same call:
48
+ result = enforcer.evaluate(
49
+ "cover.garage", "cover.open_cover",
50
+ confirmation_token=approved_token,
51
+ )
52
+ ```
53
+
54
+ ## Reading a device's profile
55
+
56
+ `ProfileStore` resolves the effective profile after inheritance and defaults. Use a file backend to persist profiles under your HA config:
57
+
58
+ ```python
59
+ from mesa_core import ProfileStore
60
+ from mesa_core.backends import JsonFileBackend
61
+
62
+ store = ProfileStore(backend=JsonFileBackend("/config/mesa/"))
63
+ profile = store.get_effective("light.living_room_ceiling")
64
+ profile.operational_boundaries.control_mode # ControlMode.AUTONOMOUS
65
+ ```
66
+
67
+ ## Exposing it to an AI agent (MCP)
68
+
69
+ Register MESA's tools into an MCP server so the agent can look up profiles and caller context for itself.
70
+
71
+ ```python
72
+ from mesa_core.mcp import register_mesa_tools
73
+
74
+ register_mesa_tools(store, adapter="fastmcp", server=app)
75
+ ```
76
+
77
+ Adapters ship for FastMCP and the MCP Python SDK (`pip install "mesa-core[fastmcp]"` or `"mesa-core[mcp]"`). Any other framework can implement a small registration protocol.
78
+
79
+ ## Loading profiles shipped by integrations
80
+
81
+ An HA integration can ship a `mesa_profile.json` describing its own devices. Load it with:
82
+
83
+ ```python
84
+ from mesa_core import import_from_integration
85
+
86
+ profile = import_from_integration("/config/custom_components/my_integration")
87
+ if profile is not None:
88
+ store.set_domain_profile(profile.entity_id, profile)
89
+ ```
90
+
91
+ ## Documentation
92
+
93
+ - [MESA Overview](documents/MESA-Overview.md) - the problem MESA solves, in plain terms
94
+ - [Getting Started](documents/MESA-Getting-Started.md) - write your first profile
95
+ - [Specification](documents/MESA-Specification.md) - the full normative reference
96
+ - [Enrichment](documents/MESA-Enrichment.md) - optional advanced domains
97
+ - [Module Proposal](documents/MESA-Module.md) - how this library is built
98
+
99
+ ## Status
100
+
101
+ mesa-core v1.0 is ready for use: profile storage and inheritance, enforcement with confirmation, the MCP retrieval tools, and privacy controls are all implemented.
102
+
103
+ ```bash
104
+ git clone https://github.com/sfox38/mesa-core
105
+ cd mesa-core
106
+ pip install -e ".[dev]"
107
+ pytest tests/ -v # test suite
108
+ ruff check . && mypy # lint and type check
109
+ ```
@@ -0,0 +1,49 @@
1
+ # Security Policy
2
+
3
+ mesa-core is a safety enforcement component: it decides whether an AI agent's action against a smart-home entity is permitted. A bug that causes it to allow something it should block is a security issue, not just a defect. This policy describes what to report and how.
4
+
5
+ ## Supported versions
6
+
7
+ | Version | Supported |
8
+ |---|---|
9
+ | 1.0.x | Yes |
10
+ | < 1.0 | No |
11
+
12
+ Security fixes are released as patch versions and noted in the changelog.
13
+
14
+ ## Reporting a vulnerability
15
+
16
+ Please do not open a public issue for a suspected vulnerability.
17
+
18
+ Report it privately by either:
19
+
20
+ - GitHub's "Report a vulnerability" button under the repository's Security tab (a private advisory), or
21
+ - email to sfox38@gmail.com with "mesa-core security" in the subject.
22
+
23
+ Include the affected version, the impact, and a minimal profile plus service call that reproduces it. mesa-core has zero runtime dependencies, so a reproduction is usually a small self-contained Python snippet.
24
+
25
+ This is a solo-maintained project. Expect an acknowledgement within five business days and an assessment of severity and fix timeline shortly after. Please allow a reasonable window for a fix before any public disclosure.
26
+
27
+ ## What is in scope
28
+
29
+ The bug that matters most here is a fail-open: an outcome that should be denied but is allowed. For example:
30
+
31
+ - A `control_mode: prohibited` or `read_only` entity that is nonetheless actionable in enforced mode.
32
+ - An active `declared_limit`, `temporal_constraint`, or privacy classification that fails to apply when it should.
33
+ - Conflict resolution (Rules A-E) loosening a value that should only tighten, for example an inherited `prohibited` being downgraded.
34
+ - The confirmation protocol (Section 6.6) accepting a token that does not bind to the exact entity, service, and parameters challenged, or honouring a reused single-use token.
35
+ - An evaluation error that opens access rather than failing closed.
36
+
37
+ Reports framed against a specific spec section are the most actionable.
38
+
39
+ ## What is out of scope
40
+
41
+ These are documented design boundaries, not vulnerabilities. They are described in spec Section 3 (Security Considerations) and the project's design notes:
42
+
43
+ - Deliberately deceptive agents. MESA's threat model assumes cooperative agents. A malicious agent that ignores boundaries is out of scope at the metadata layer; Home Assistant's native access control is the required backstop. Enforced mode and native HA permissions are meant to be used together, and neither alone is sufficient.
44
+ - Global state invariants across calls. mesa-core evaluates one call at a time. It does not solve cross-entity transition invariants (for example "never leave the door unlocked while the alarm is disarmed"); that is an automation-layer concern.
45
+ - Non-canonical inputs. mesa-core matches service names, entity IDs, and state values exactly against their canonical Home Assistant forms. Canonicalising incoming calls before evaluation is the host's responsibility (spec Section 6); a non-canonical call that slips past a boundary is a host integration bug, not a mesa-core vulnerability.
46
+ - Over-restriction via erroneous or poisoned profiles. A profile that wrongly over-restricts is handled by the removal path in spec Section 3, not as a security report.
47
+
48
+ If you are unsure whether something is in scope, report it privately anyway and we will sort it out.
49
+