safety-harness 0.2.1__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.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,8 @@
1
+ Physical AI Safety Harness
2
+ Copyright 2026 Kaoru Naganuma
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.4
2
+ Name: safety-harness
3
+ Version: 0.2.1
4
+ Summary: Default-deny precondition gate for physical AI actuators: permission, not detection.
5
+ Author-email: Kaoru Naganuma <kaoru.naganuma@gmail.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/naganumakr/safety-harness
8
+ Project-URL: Repository, https://github.com/naganumakr/safety-harness
9
+ Project-URL: Issues, https://github.com/naganumakr/safety-harness/issues
10
+ Project-URL: Design doc, https://claude.ai/artifact/V1cBKhjD94CZBj4D8kQjdU
11
+ Keywords: robotics,safety,physical-ai,isaac-lab,iso-15066
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ License-File: NOTICE
26
+ Requires-Dist: pyyaml>=6.0
27
+ Dynamic: license-file
28
+
29
+ # Physical AI Safety Harness
30
+
31
+ [![tests](https://github.com/naganumakr/safety-harness/actions/workflows/tests.yml/badge.svg)](https://github.com/naganumakr/safety-harness/actions/workflows/tests.yml)
32
+ [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
33
+
34
+ A default-deny precondition gate for physical actuators. Every action a robot proposes — grasp,
35
+ place, reach, anything else you register — must earn a `PERMIT` from measured, structured
36
+ evidence before it executes. No evidence, or a failed check, or an adapter that raises: `BLOCK`.
37
+ Permission, not detection.
38
+
39
+ Full design spec, architecture, worked examples, test/validation record, and roadmap:
40
+ **[Physical AI Safety Harness — design doc](https://claude.ai/artifact/V1cBKhjD94CZBj4D8kQjdU)**.
41
+
42
+ ## Status
43
+
44
+ Reference implementation, not yet independently assessed. Validated against one robot (a Franka
45
+ Panda arm) in one simulator (Isaac Lab), with 75 automated unit/fuzz/mutation/black-box tests and
46
+ 7 live hazard-scenario recordings. It has **not** been reviewed by a functional-safety assessor
47
+ against IEC 61508, ISO 13849, or ISO 10218/TS 15066 — see the design doc's Scope & Non-Goals
48
+ section for what's out of scope today (joint-space kinematic checks, certified numeric
49
+ thresholds, data-protection handling of logged human-position data). Treat this as engineering
50
+ evidence, not a certification.
51
+
52
+ ## What's here
53
+
54
+ - `safety_harness/schema.py` — the data contract (`WorldState`, `Action`, `Decision`, and friends).
55
+ `SCHEMA_VERSION` tracks this contract specifically; bump it deliberately (see the design doc's
56
+ Version History).
57
+ - `safety_harness/engine.py` — `ActuatorGate.gate()`, the single decision entry point.
58
+ - `safety_harness/preconditions.py` — the registered precondition checks (24 at last count:
59
+ object/target safety, placement, agent proximity incl. ISO/TS 15066, robot self-limits,
60
+ environmental signals).
61
+ - `safety_harness/action_schema.py` — the YAML-driven registry mapping action types to the checks
62
+ they must pass (`configs/example_action_schema.yaml` is the reference wiring).
63
+ - `tests/` — unit tests, mutation/random-fuzz tests, and reflection-driven black-box contract
64
+ tests.
65
+
66
+ Robot-specific behavior lives entirely behind four adapter interfaces
67
+ (`PerceptionAdapter`, `DynamicsAdapter`, `FallbackController`, `Logger`) so the engine and checks
68
+ are robot-agnostic. Only an Isaac Lab / Franka adapter exists today.
69
+
70
+ ## Install & test
71
+
72
+ Not on PyPI yet — install straight from GitHub:
73
+
74
+ ```bash
75
+ pip install git+https://github.com/naganumakr/safety-harness.git
76
+ ```
77
+
78
+ Or for local development (editable, so edits to `safety_harness/` take effect immediately):
79
+
80
+ ```bash
81
+ git clone https://github.com/naganumakr/safety-harness.git
82
+ cd safety-harness
83
+ pip install -e .
84
+ python -m unittest discover -s tests -p "test_*.py"
85
+ ```
86
+
87
+ ## Usage
88
+
89
+ ```python
90
+ from safety_harness import ActionSchemaRegistry, ActuatorGate
91
+ from safety_harness.adapters import FreezeInPlaceFallback, InMemoryLogger
92
+ from safety_harness.adapters.isaac_lab import (
93
+ IsaacLabCubeStackPerceptionAdapter,
94
+ IsaacLabCubeStackDynamicsAdapter,
95
+ )
96
+
97
+ schema = ActionSchemaRegistry.from_yaml("configs/example_action_schema.yaml")
98
+ gate = ActuatorGate(
99
+ perception=IsaacLabCubeStackPerceptionAdapter(...), # swap for your own stack's adapter
100
+ dynamics=IsaacLabCubeStackDynamicsAdapter(...),
101
+ fallback=FreezeInPlaceFallback(),
102
+ logger=InMemoryLogger(),
103
+ schema=schema,
104
+ )
105
+
106
+ decision = gate.gate(proposed_action) # -> Decision(verdict=PERMIT|BLOCK, ...)
107
+ if decision.verdict.name == "PERMIT":
108
+ robot.execute(decision.action)
109
+ else:
110
+ robot.execute(decision.action) # the fallback action FreezeInPlaceFallback produced
111
+ ```
112
+
113
+ Nothing here is Isaac-Lab-specific except the two adapter classes — swap those for adapters
114
+ targeting your own robot stack and the engine, checks, and tests are unchanged. See "Contributing
115
+ an adapter" below.
116
+
117
+ ## License
118
+
119
+ Apache License 2.0 — see [LICENSE](LICENSE) and [NOTICE](NOTICE). The engine, the adapter
120
+ interfaces, and the conformance test suite are all open under this license: the goal is for any
121
+ robot maker to implement the four adapters for their own stack and run the same conformance suite
122
+ against it, not to license the core code per-implementation. See the design doc's Release &
123
+ Distribution section for the reasoning and the certification model this enables.
124
+
125
+ ## Contributing an adapter
126
+
127
+ 1. Implement `PerceptionAdapter`, `DynamicsAdapter`, `FallbackController`, and `Logger` for your
128
+ stack (see `safety_harness/adapters/isaac_lab.py` for the reference shape).
129
+ 2. Run the black-box and fuzz test suites against your adapter's `WorldState`/`PredictedTrajectory`
130
+ output — they're written against the interfaces, not the Isaac Lab implementation, so they
131
+ should run unmodified.
132
+ 3. Open an issue or PR with your results. Passing the conformance suite is what "compliant
133
+ adapter" means here — there's no separate certification process yet, but that's the intent
134
+ (see the design doc's Roadmap).
@@ -0,0 +1,106 @@
1
+ # Physical AI Safety Harness
2
+
3
+ [![tests](https://github.com/naganumakr/safety-harness/actions/workflows/tests.yml/badge.svg)](https://github.com/naganumakr/safety-harness/actions/workflows/tests.yml)
4
+ [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
5
+
6
+ A default-deny precondition gate for physical actuators. Every action a robot proposes — grasp,
7
+ place, reach, anything else you register — must earn a `PERMIT` from measured, structured
8
+ evidence before it executes. No evidence, or a failed check, or an adapter that raises: `BLOCK`.
9
+ Permission, not detection.
10
+
11
+ Full design spec, architecture, worked examples, test/validation record, and roadmap:
12
+ **[Physical AI Safety Harness — design doc](https://claude.ai/artifact/V1cBKhjD94CZBj4D8kQjdU)**.
13
+
14
+ ## Status
15
+
16
+ Reference implementation, not yet independently assessed. Validated against one robot (a Franka
17
+ Panda arm) in one simulator (Isaac Lab), with 75 automated unit/fuzz/mutation/black-box tests and
18
+ 7 live hazard-scenario recordings. It has **not** been reviewed by a functional-safety assessor
19
+ against IEC 61508, ISO 13849, or ISO 10218/TS 15066 — see the design doc's Scope & Non-Goals
20
+ section for what's out of scope today (joint-space kinematic checks, certified numeric
21
+ thresholds, data-protection handling of logged human-position data). Treat this as engineering
22
+ evidence, not a certification.
23
+
24
+ ## What's here
25
+
26
+ - `safety_harness/schema.py` — the data contract (`WorldState`, `Action`, `Decision`, and friends).
27
+ `SCHEMA_VERSION` tracks this contract specifically; bump it deliberately (see the design doc's
28
+ Version History).
29
+ - `safety_harness/engine.py` — `ActuatorGate.gate()`, the single decision entry point.
30
+ - `safety_harness/preconditions.py` — the registered precondition checks (24 at last count:
31
+ object/target safety, placement, agent proximity incl. ISO/TS 15066, robot self-limits,
32
+ environmental signals).
33
+ - `safety_harness/action_schema.py` — the YAML-driven registry mapping action types to the checks
34
+ they must pass (`configs/example_action_schema.yaml` is the reference wiring).
35
+ - `tests/` — unit tests, mutation/random-fuzz tests, and reflection-driven black-box contract
36
+ tests.
37
+
38
+ Robot-specific behavior lives entirely behind four adapter interfaces
39
+ (`PerceptionAdapter`, `DynamicsAdapter`, `FallbackController`, `Logger`) so the engine and checks
40
+ are robot-agnostic. Only an Isaac Lab / Franka adapter exists today.
41
+
42
+ ## Install & test
43
+
44
+ Not on PyPI yet — install straight from GitHub:
45
+
46
+ ```bash
47
+ pip install git+https://github.com/naganumakr/safety-harness.git
48
+ ```
49
+
50
+ Or for local development (editable, so edits to `safety_harness/` take effect immediately):
51
+
52
+ ```bash
53
+ git clone https://github.com/naganumakr/safety-harness.git
54
+ cd safety-harness
55
+ pip install -e .
56
+ python -m unittest discover -s tests -p "test_*.py"
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ ```python
62
+ from safety_harness import ActionSchemaRegistry, ActuatorGate
63
+ from safety_harness.adapters import FreezeInPlaceFallback, InMemoryLogger
64
+ from safety_harness.adapters.isaac_lab import (
65
+ IsaacLabCubeStackPerceptionAdapter,
66
+ IsaacLabCubeStackDynamicsAdapter,
67
+ )
68
+
69
+ schema = ActionSchemaRegistry.from_yaml("configs/example_action_schema.yaml")
70
+ gate = ActuatorGate(
71
+ perception=IsaacLabCubeStackPerceptionAdapter(...), # swap for your own stack's adapter
72
+ dynamics=IsaacLabCubeStackDynamicsAdapter(...),
73
+ fallback=FreezeInPlaceFallback(),
74
+ logger=InMemoryLogger(),
75
+ schema=schema,
76
+ )
77
+
78
+ decision = gate.gate(proposed_action) # -> Decision(verdict=PERMIT|BLOCK, ...)
79
+ if decision.verdict.name == "PERMIT":
80
+ robot.execute(decision.action)
81
+ else:
82
+ robot.execute(decision.action) # the fallback action FreezeInPlaceFallback produced
83
+ ```
84
+
85
+ Nothing here is Isaac-Lab-specific except the two adapter classes — swap those for adapters
86
+ targeting your own robot stack and the engine, checks, and tests are unchanged. See "Contributing
87
+ an adapter" below.
88
+
89
+ ## License
90
+
91
+ Apache License 2.0 — see [LICENSE](LICENSE) and [NOTICE](NOTICE). The engine, the adapter
92
+ interfaces, and the conformance test suite are all open under this license: the goal is for any
93
+ robot maker to implement the four adapters for their own stack and run the same conformance suite
94
+ against it, not to license the core code per-implementation. See the design doc's Release &
95
+ Distribution section for the reasoning and the certification model this enables.
96
+
97
+ ## Contributing an adapter
98
+
99
+ 1. Implement `PerceptionAdapter`, `DynamicsAdapter`, `FallbackController`, and `Logger` for your
100
+ stack (see `safety_harness/adapters/isaac_lab.py` for the reference shape).
101
+ 2. Run the black-box and fuzz test suites against your adapter's `WorldState`/`PredictedTrajectory`
102
+ output — they're written against the interfaces, not the Isaac Lab implementation, so they
103
+ should run unmodified.
104
+ 3. Open an issue or PR with your results. Passing the conformance suite is what "compliant
105
+ adapter" means here — there's no separate certification process yet, but that's the intent
106
+ (see the design doc's Roadmap).
@@ -0,0 +1,35 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "safety-harness"
7
+ version = "0.2.1"
8
+ description = "Default-deny precondition gate for physical AI actuators: permission, not detection."
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.9"
12
+ authors = [{ name = "Kaoru Naganuma", email = "kaoru.naganuma@gmail.com" }]
13
+ keywords = ["robotics", "safety", "physical-ai", "isaac-lab", "iso-15066"]
14
+ dependencies = ["pyyaml>=6.0"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.9",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Operating System :: OS Independent",
24
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
25
+ "Topic :: Software Development :: Libraries",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/naganumakr/safety-harness"
30
+ Repository = "https://github.com/naganumakr/safety-harness"
31
+ Issues = "https://github.com/naganumakr/safety-harness/issues"
32
+ "Design doc" = "https://claude.ai/artifact/V1cBKhjD94CZBj4D8kQjdU"
33
+
34
+ [tool.setuptools.packages.find]
35
+ include = ["safety_harness*"]
@@ -0,0 +1,40 @@
1
+ from .action_schema import ActionSchemaRegistry
2
+ from .engine import ActuatorGate, PerceptionFailure
3
+ from .schema import (
4
+ SCHEMA_VERSION,
5
+ Action,
6
+ Decision,
7
+ DecisionVerdict,
8
+ EnvironmentSignals,
9
+ FallConsequence,
10
+ HazardTag,
11
+ Pose,
12
+ PredictedTrajectory,
13
+ PreconditionResult,
14
+ RobotProprioception,
15
+ TrackedAgent,
16
+ TrackedObject,
17
+ TrajectoryPoint,
18
+ WorldState,
19
+ )
20
+
21
+ __all__ = [
22
+ "ActionSchemaRegistry",
23
+ "ActuatorGate",
24
+ "PerceptionFailure",
25
+ "SCHEMA_VERSION",
26
+ "Action",
27
+ "Decision",
28
+ "DecisionVerdict",
29
+ "EnvironmentSignals",
30
+ "FallConsequence",
31
+ "HazardTag",
32
+ "Pose",
33
+ "PredictedTrajectory",
34
+ "PreconditionResult",
35
+ "RobotProprioception",
36
+ "TrackedAgent",
37
+ "TrackedObject",
38
+ "TrajectoryPoint",
39
+ "WorldState",
40
+ ]
@@ -0,0 +1,65 @@
1
+ """Declarative action-type -> required-precondition mapping.
2
+
3
+ A robot team edits the YAML config, not this file (design doc: "Action Precondition Schemas",
4
+ "Reference Module Design"). An action type with no registered schema is unsafe by default -- see
5
+ ``run_checks`` -- which enforces "unsafe unless confirmed" even at the registration level, not just
6
+ inside individual checks.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from dataclasses import dataclass
12
+
13
+ import yaml
14
+
15
+ from .preconditions import REGISTRY
16
+ from .schema import Action, PredictedTrajectory, PreconditionResult, WorldState
17
+
18
+
19
+ @dataclass(frozen=True)
20
+ class ActionTypeSchema:
21
+ action_type: str
22
+ checks: tuple # each element: {"name": <registry key>, "kwargs": {...}}
23
+
24
+
25
+ class ActionSchemaRegistry:
26
+ def __init__(self, schemas: dict):
27
+ self._schemas = schemas
28
+
29
+ @classmethod
30
+ def from_yaml(cls, path: str) -> "ActionSchemaRegistry":
31
+ with open(path) as f:
32
+ raw = yaml.safe_load(f) or {}
33
+ return cls.from_dict(raw)
34
+
35
+ @classmethod
36
+ def from_dict(cls, raw: dict) -> "ActionSchemaRegistry":
37
+ schemas = {}
38
+ for action_type, spec in (raw.get("action_types") or {}).items():
39
+ checks = tuple(spec.get("checks", []))
40
+ for check in checks:
41
+ if check["name"] not in REGISTRY:
42
+ raise ValueError(f"unknown precondition check {check['name']!r} for action type {action_type!r}")
43
+ schemas[action_type] = ActionTypeSchema(action_type=action_type, checks=checks)
44
+ return cls(schemas)
45
+
46
+ def run_checks(
47
+ self, action: Action, state: WorldState, trajectory: PredictedTrajectory,
48
+ ) -> tuple:
49
+ schema = self._schemas.get(action.action_type)
50
+ if schema is None:
51
+ # No declared schema -> no confirmed preconditions -> never permitted. Register the
52
+ # action type explicitly (even with an empty check list) to allow it through.
53
+ return (
54
+ PreconditionResult(
55
+ name="action_type_registered",
56
+ satisfied=False,
57
+ reason=f"action type {action.action_type!r} has no registered schema",
58
+ ),
59
+ )
60
+ results = []
61
+ for check in schema.checks:
62
+ fn = REGISTRY[check["name"]]
63
+ kwargs = check.get("kwargs", {}) or {}
64
+ results.append(fn(state, action, trajectory, **kwargs))
65
+ return tuple(results)
@@ -0,0 +1,11 @@
1
+ from .base import DynamicsAdapter, FallbackController, Logger, PerceptionAdapter
2
+ from .simple import FreezeInPlaceFallback, InMemoryLogger
3
+
4
+ __all__ = [
5
+ "DynamicsAdapter",
6
+ "FallbackController",
7
+ "Logger",
8
+ "PerceptionAdapter",
9
+ "FreezeInPlaceFallback",
10
+ "InMemoryLogger",
11
+ ]
@@ -0,0 +1,36 @@
1
+ """Adapter interfaces a robot team implements.
2
+
3
+ The engine (engine.py) never imports a robot-specific module -- only these four abstract
4
+ interfaces. See the design doc's "Reference Module Design" and "Stack-by-Stack Integration"
5
+ sections for what each wraps on a given robot stack.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from abc import ABC, abstractmethod
11
+
12
+ from ..schema import Action, Decision, PredictedTrajectory, WorldState
13
+
14
+
15
+ class PerceptionAdapter(ABC):
16
+ @abstractmethod
17
+ def get_world_state(self) -> WorldState:
18
+ """Read whatever perception this robot already runs and return it in the fixed schema."""
19
+
20
+
21
+ class DynamicsAdapter(ABC):
22
+ @abstractmethod
23
+ def predict_trajectory(self, state: WorldState, action: Action, horizon_s: float) -> PredictedTrajectory:
24
+ """Forward-simulate the proposed action using this robot's own kinematics/physics model."""
25
+
26
+
27
+ class FallbackController(ABC):
28
+ @abstractmethod
29
+ def execute(self, state: WorldState) -> Action:
30
+ """Return this robot's safe fallback action given the current state (freeze, retract, ...)."""
31
+
32
+
33
+ class Logger(ABC):
34
+ @abstractmethod
35
+ def record(self, decision: Decision, state: WorldState) -> None:
36
+ """Write the decision to whatever telemetry sink this robot already uses."""