cyandoor 0.1.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.
- cyandoor-0.1.0/.gitignore +22 -0
- cyandoor-0.1.0/LICENSE +202 -0
- cyandoor-0.1.0/PKG-INFO +124 -0
- cyandoor-0.1.0/README.md +103 -0
- cyandoor-0.1.0/pyproject.toml +84 -0
- cyandoor-0.1.0/src/cyandoor/__init__.py +45 -0
- cyandoor-0.1.0/src/cyandoor/_base.py +29 -0
- cyandoor-0.1.0/src/cyandoor/candidates.py +145 -0
- cyandoor-0.1.0/src/cyandoor/canonical.py +75 -0
- cyandoor-0.1.0/src/cyandoor/evidence.py +147 -0
- cyandoor-0.1.0/src/cyandoor/py.typed +1 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.so
|
|
5
|
+
.pytest_cache/
|
|
6
|
+
.mypy_cache/
|
|
7
|
+
.ruff_cache/
|
|
8
|
+
.coverage
|
|
9
|
+
htmlcov/
|
|
10
|
+
|
|
11
|
+
# Virtual environments
|
|
12
|
+
.venv/
|
|
13
|
+
|
|
14
|
+
# Packaging
|
|
15
|
+
build/
|
|
16
|
+
dist/
|
|
17
|
+
*.egg-info/
|
|
18
|
+
|
|
19
|
+
# Editors / OS
|
|
20
|
+
.DS_Store
|
|
21
|
+
.idea/
|
|
22
|
+
.vscode/
|
cyandoor-0.1.0/LICENSE
ADDED
|
@@ -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.
|
cyandoor-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cyandoor
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed, verifiable candidate-set manifests for AI agent decisions
|
|
5
|
+
Project-URL: Repository, https://github.com/cyandoor/cyandoor
|
|
6
|
+
Project-URL: Issues, https://github.com/cyandoor/cyandoor/issues
|
|
7
|
+
Author: CyanDoor
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ai-agents,decision-evidence,decision-intelligence
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
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.12
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Requires-Dist: pydantic<3,>=2
|
|
19
|
+
Requires-Dist: rfc8785<1,>=0.1
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
<p align="center">
|
|
23
|
+
<img src="docs/assets/cyandoor-wordmark.svg" alt="CyanDoor" width="360">
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
<p align="center"><strong>Decision intelligence for AI agents.</strong><br>Better decisions, learned from outcomes.</p>
|
|
27
|
+
|
|
28
|
+
<p align="center">
|
|
29
|
+
<a href="https://github.com/cyandoor/cyandoor/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/cyandoor/cyandoor/actions/workflows/ci.yml/badge.svg"></a>
|
|
30
|
+
<img alt="Python 3.12+" src="https://img.shields.io/badge/python-3.12%2B-101820">
|
|
31
|
+
<a href="LICENSE"><img alt="Apache-2.0" src="https://img.shields.io/badge/license-Apache--2.0-087F89"></a>
|
|
32
|
+
</p>
|
|
33
|
+
|
|
34
|
+
CyanDoor is building an outcome-trained decision layer for AI agents: connect decision-time evidence and eligible candidate actions with downstream outcomes, then use trustworthy history to guide the next choice.
|
|
35
|
+
|
|
36
|
+
## Current release
|
|
37
|
+
|
|
38
|
+
Version 0.1.0 is an early, deliberately narrow Decision-Evidence foundation. It provides typed, deterministic candidate-set manifests: describe candidate identities, freeze the ordered set before outcomes are observed, calculate its canonical digest, and verify later that the sealed manifest has not changed.
|
|
39
|
+
|
|
40
|
+
It does **not** yet include runtime connectors, persistence, Decision Audit/headroom, policy learning, cloud sync, or automatic agent optimization. Coding agents are the initial evidence environment, not the long-term product boundary.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
Requires Python 3.12 or newer.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install cyandoor
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Real example
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from datetime import UTC, datetime
|
|
54
|
+
|
|
55
|
+
from cyandoor import (
|
|
56
|
+
CandidateSetMember,
|
|
57
|
+
DraftCandidateSetManifest,
|
|
58
|
+
seal_candidate_set,
|
|
59
|
+
verify_candidate_set,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
now = datetime.now(UTC)
|
|
63
|
+
draft = DraftCandidateSetManifest(
|
|
64
|
+
candidate_set_id="verification-strategies",
|
|
65
|
+
candidate_set_version="1",
|
|
66
|
+
decision_space_id="execution_strategy",
|
|
67
|
+
members=(
|
|
68
|
+
CandidateSetMember(
|
|
69
|
+
order_index=0,
|
|
70
|
+
candidate_id="run-tests-first@1",
|
|
71
|
+
action_identity_digest="sha256:" + "1" * 64,
|
|
72
|
+
),
|
|
73
|
+
CandidateSetMember(
|
|
74
|
+
order_index=1,
|
|
75
|
+
candidate_id="inspect-failure-first@1",
|
|
76
|
+
action_identity_digest="sha256:" + "2" * 64,
|
|
77
|
+
),
|
|
78
|
+
),
|
|
79
|
+
created_at=now,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
sealed = seal_candidate_set(
|
|
83
|
+
draft,
|
|
84
|
+
eligibility_rule_id="default",
|
|
85
|
+
eligibility_rule_version="1",
|
|
86
|
+
evidence_eligibility_cutoff_at=now,
|
|
87
|
+
sealed_at=now,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
assert verify_candidate_set(sealed)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Why Decision Evidence?
|
|
94
|
+
|
|
95
|
+
Traces reconstruct a run. CyanDoor focuses on the choice inside it: what was available and eligible, what was selected, what evidence existed at the cutoff, and whether that record remains verifiable after the outcome is known.
|
|
96
|
+
|
|
97
|
+
The long-term relationship is:
|
|
98
|
+
|
|
99
|
+
```text
|
|
100
|
+
decision-time evidence + eligible candidate actions + historical outcomes
|
|
101
|
+
-> better next decision
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Product breadth belongs in neutral architecture. Public availability belongs only in tested capabilities.
|
|
105
|
+
|
|
106
|
+
## Design principles
|
|
107
|
+
|
|
108
|
+
- agent-agnostic contracts, with integrations claimed only after validation;
|
|
109
|
+
- explicit provenance and evidence-strength states;
|
|
110
|
+
- immutable, strictly validated models;
|
|
111
|
+
- deterministic canonical serialization and digests;
|
|
112
|
+
- no causal or improvement claim without supporting evidence.
|
|
113
|
+
|
|
114
|
+
The public website and expanded documentation are being developed in [`cyandoor/cyandoor-web`](https://github.com/cyandoor/cyandoor-web). Until its canonical domain is live, this README remains the release-accurate technical starting point.
|
|
115
|
+
|
|
116
|
+
## Contributing and status
|
|
117
|
+
|
|
118
|
+
The repository is in early alpha. Use [GitHub Issues](https://github.com/cyandoor/cyandoor/issues) for focused bug reports and technical discussion.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
CyanDoor is licensed under the [Apache License 2.0](LICENSE).
|
|
123
|
+
|
|
124
|
+
> Evidence is the beginning. Better decisions are the outcome.
|
cyandoor-0.1.0/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="docs/assets/cyandoor-wordmark.svg" alt="CyanDoor" width="360">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>Decision intelligence for AI agents.</strong><br>Better decisions, learned from outcomes.</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/cyandoor/cyandoor/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/cyandoor/cyandoor/actions/workflows/ci.yml/badge.svg"></a>
|
|
9
|
+
<img alt="Python 3.12+" src="https://img.shields.io/badge/python-3.12%2B-101820">
|
|
10
|
+
<a href="LICENSE"><img alt="Apache-2.0" src="https://img.shields.io/badge/license-Apache--2.0-087F89"></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
CyanDoor is building an outcome-trained decision layer for AI agents: connect decision-time evidence and eligible candidate actions with downstream outcomes, then use trustworthy history to guide the next choice.
|
|
14
|
+
|
|
15
|
+
## Current release
|
|
16
|
+
|
|
17
|
+
Version 0.1.0 is an early, deliberately narrow Decision-Evidence foundation. It provides typed, deterministic candidate-set manifests: describe candidate identities, freeze the ordered set before outcomes are observed, calculate its canonical digest, and verify later that the sealed manifest has not changed.
|
|
18
|
+
|
|
19
|
+
It does **not** yet include runtime connectors, persistence, Decision Audit/headroom, policy learning, cloud sync, or automatic agent optimization. Coding agents are the initial evidence environment, not the long-term product boundary.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
Requires Python 3.12 or newer.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install cyandoor
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Real example
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from datetime import UTC, datetime
|
|
33
|
+
|
|
34
|
+
from cyandoor import (
|
|
35
|
+
CandidateSetMember,
|
|
36
|
+
DraftCandidateSetManifest,
|
|
37
|
+
seal_candidate_set,
|
|
38
|
+
verify_candidate_set,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
now = datetime.now(UTC)
|
|
42
|
+
draft = DraftCandidateSetManifest(
|
|
43
|
+
candidate_set_id="verification-strategies",
|
|
44
|
+
candidate_set_version="1",
|
|
45
|
+
decision_space_id="execution_strategy",
|
|
46
|
+
members=(
|
|
47
|
+
CandidateSetMember(
|
|
48
|
+
order_index=0,
|
|
49
|
+
candidate_id="run-tests-first@1",
|
|
50
|
+
action_identity_digest="sha256:" + "1" * 64,
|
|
51
|
+
),
|
|
52
|
+
CandidateSetMember(
|
|
53
|
+
order_index=1,
|
|
54
|
+
candidate_id="inspect-failure-first@1",
|
|
55
|
+
action_identity_digest="sha256:" + "2" * 64,
|
|
56
|
+
),
|
|
57
|
+
),
|
|
58
|
+
created_at=now,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
sealed = seal_candidate_set(
|
|
62
|
+
draft,
|
|
63
|
+
eligibility_rule_id="default",
|
|
64
|
+
eligibility_rule_version="1",
|
|
65
|
+
evidence_eligibility_cutoff_at=now,
|
|
66
|
+
sealed_at=now,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
assert verify_candidate_set(sealed)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Why Decision Evidence?
|
|
73
|
+
|
|
74
|
+
Traces reconstruct a run. CyanDoor focuses on the choice inside it: what was available and eligible, what was selected, what evidence existed at the cutoff, and whether that record remains verifiable after the outcome is known.
|
|
75
|
+
|
|
76
|
+
The long-term relationship is:
|
|
77
|
+
|
|
78
|
+
```text
|
|
79
|
+
decision-time evidence + eligible candidate actions + historical outcomes
|
|
80
|
+
-> better next decision
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Product breadth belongs in neutral architecture. Public availability belongs only in tested capabilities.
|
|
84
|
+
|
|
85
|
+
## Design principles
|
|
86
|
+
|
|
87
|
+
- agent-agnostic contracts, with integrations claimed only after validation;
|
|
88
|
+
- explicit provenance and evidence-strength states;
|
|
89
|
+
- immutable, strictly validated models;
|
|
90
|
+
- deterministic canonical serialization and digests;
|
|
91
|
+
- no causal or improvement claim without supporting evidence.
|
|
92
|
+
|
|
93
|
+
The public website and expanded documentation are being developed in [`cyandoor/cyandoor-web`](https://github.com/cyandoor/cyandoor-web). Until its canonical domain is live, this README remains the release-accurate technical starting point.
|
|
94
|
+
|
|
95
|
+
## Contributing and status
|
|
96
|
+
|
|
97
|
+
The repository is in early alpha. Use [GitHub Issues](https://github.com/cyandoor/cyandoor/issues) for focused bug reports and technical discussion.
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
CyanDoor is licensed under the [Apache License 2.0](LICENSE).
|
|
102
|
+
|
|
103
|
+
> Evidence is the beginning. Better decisions are the outcome.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "cyandoor"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Typed, verifiable candidate-set manifests for AI agent decisions"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "CyanDoor" },
|
|
11
|
+
]
|
|
12
|
+
keywords = ["ai-agents", "decision-intelligence", "decision-evidence"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: Apache Software License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Typing :: Typed",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"pydantic>=2,<3",
|
|
23
|
+
"rfc8785>=0.1,<1",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Repository = "https://github.com/cyandoor/cyandoor"
|
|
28
|
+
Issues = "https://github.com/cyandoor/cyandoor/issues"
|
|
29
|
+
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["hatchling>=1.27,<1.28"]
|
|
32
|
+
build-backend = "hatchling.build"
|
|
33
|
+
|
|
34
|
+
[dependency-groups]
|
|
35
|
+
dev = [
|
|
36
|
+
"mypy>=1.15,<2",
|
|
37
|
+
"pytest>=8,<9",
|
|
38
|
+
"ruff>=0.12,<1",
|
|
39
|
+
"twine>=6,<7",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["src/cyandoor"]
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.sdist]
|
|
46
|
+
include = [
|
|
47
|
+
"/LICENSE",
|
|
48
|
+
"/README.md",
|
|
49
|
+
"/pyproject.toml",
|
|
50
|
+
"/src/cyandoor",
|
|
51
|
+
]
|
|
52
|
+
exclude = [
|
|
53
|
+
"/.github",
|
|
54
|
+
"/.gitignore",
|
|
55
|
+
"/.gitkeep",
|
|
56
|
+
"/.python-version",
|
|
57
|
+
"/ARCHITECTURE_DECISIONS.md",
|
|
58
|
+
"/config",
|
|
59
|
+
"/docs",
|
|
60
|
+
"/tests",
|
|
61
|
+
"/uv.lock",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[tool.pytest.ini_options]
|
|
65
|
+
addopts = "-ra --strict-config --strict-markers"
|
|
66
|
+
testpaths = ["tests"]
|
|
67
|
+
|
|
68
|
+
[tool.ruff]
|
|
69
|
+
target-version = "py312"
|
|
70
|
+
line-length = 100
|
|
71
|
+
src = ["src", "tests"]
|
|
72
|
+
exclude = ["docs/MVP_SPEC_v0.5.md", "docs/MVP_SPEC_v0.5.1.md", "docs/MVP_SPEC_v0.5.2.md"]
|
|
73
|
+
|
|
74
|
+
[tool.ruff.lint]
|
|
75
|
+
select = ["E4", "E7", "E9", "F", "I", "UP", "B", "SIM", "RUF"]
|
|
76
|
+
|
|
77
|
+
[tool.ruff.format]
|
|
78
|
+
quote-style = "double"
|
|
79
|
+
indent-style = "space"
|
|
80
|
+
|
|
81
|
+
[tool.mypy]
|
|
82
|
+
python_version = "3.12"
|
|
83
|
+
strict = true
|
|
84
|
+
mypy_path = "src"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Public API for CyanDoor's candidate-set evidence core."""
|
|
2
|
+
|
|
3
|
+
from cyandoor.candidates import (
|
|
4
|
+
ActionIdentity,
|
|
5
|
+
CandidateSetMember,
|
|
6
|
+
DraftCandidateSetManifest,
|
|
7
|
+
SealedCandidateSetManifest,
|
|
8
|
+
action_identity_digest,
|
|
9
|
+
candidate_set_manifest_digest,
|
|
10
|
+
seal_candidate_set,
|
|
11
|
+
verify_candidate_set,
|
|
12
|
+
)
|
|
13
|
+
from cyandoor.evidence import (
|
|
14
|
+
ContentObjectReference,
|
|
15
|
+
DerivedValue,
|
|
16
|
+
InferredValue,
|
|
17
|
+
NativeEventReference,
|
|
18
|
+
NotApplicableValue,
|
|
19
|
+
ObservedValue,
|
|
20
|
+
OTelLogReference,
|
|
21
|
+
OTelSpanReference,
|
|
22
|
+
RedactedValue,
|
|
23
|
+
UnavailableValue,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"ActionIdentity",
|
|
28
|
+
"CandidateSetMember",
|
|
29
|
+
"ContentObjectReference",
|
|
30
|
+
"DerivedValue",
|
|
31
|
+
"DraftCandidateSetManifest",
|
|
32
|
+
"InferredValue",
|
|
33
|
+
"NativeEventReference",
|
|
34
|
+
"NotApplicableValue",
|
|
35
|
+
"OTelLogReference",
|
|
36
|
+
"OTelSpanReference",
|
|
37
|
+
"ObservedValue",
|
|
38
|
+
"RedactedValue",
|
|
39
|
+
"SealedCandidateSetManifest",
|
|
40
|
+
"UnavailableValue",
|
|
41
|
+
"action_identity_digest",
|
|
42
|
+
"candidate_set_manifest_digest",
|
|
43
|
+
"seal_candidate_set",
|
|
44
|
+
"verify_candidate_set",
|
|
45
|
+
]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Shared strict model and scalar types."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from typing import Annotated
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, ConfigDict, StringConstraints
|
|
9
|
+
|
|
10
|
+
Digest = Annotated[str, StringConstraints(pattern=r"^sha256:[0-9a-f]{64}$")]
|
|
11
|
+
NamespacedKey = Annotated[
|
|
12
|
+
str,
|
|
13
|
+
StringConstraints(pattern=r"^[a-z][a-z0-9_-]*(?:\.[a-z][a-z0-9_-]*)+$"),
|
|
14
|
+
]
|
|
15
|
+
NonEmptyString = Annotated[str, StringConstraints(min_length=1)]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class StrictModel(BaseModel):
|
|
19
|
+
"""Immutable model with strict input and no undeclared fields."""
|
|
20
|
+
|
|
21
|
+
model_config = ConfigDict(strict=True, frozen=True, extra="forbid")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def require_aware(value: datetime) -> datetime:
|
|
25
|
+
"""Reject timestamps without a UTC offset."""
|
|
26
|
+
|
|
27
|
+
if value.tzinfo is None or value.utcoffset() is None:
|
|
28
|
+
raise ValueError("timestamp must be timezone-aware")
|
|
29
|
+
return value
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Typed action identities and immutable candidate-set manifests."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hmac
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from typing import Annotated, Literal
|
|
8
|
+
|
|
9
|
+
from pydantic import Field, field_validator, model_validator
|
|
10
|
+
|
|
11
|
+
from cyandoor._base import Digest, NamespacedKey, NonEmptyString, StrictModel, require_aware
|
|
12
|
+
from cyandoor.canonical import canonical_digest, canonical_timestamp
|
|
13
|
+
from cyandoor.evidence import EvidenceDigest, EvidenceString
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ActionIdentity(StrictModel):
|
|
17
|
+
canonical_id: NonEmptyString
|
|
18
|
+
action_kind: NamespacedKey
|
|
19
|
+
source_type: NamespacedKey
|
|
20
|
+
source_locator: EvidenceString
|
|
21
|
+
source_revision: EvidenceString
|
|
22
|
+
content_digest: EvidenceDigest
|
|
23
|
+
config_digest: EvidenceDigest
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class CandidateSetMember(StrictModel):
|
|
27
|
+
order_index: Annotated[int, Field(ge=0)]
|
|
28
|
+
candidate_id: NonEmptyString
|
|
29
|
+
action_identity_digest: Digest
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _validate_members(members: tuple[CandidateSetMember, ...]) -> None:
|
|
33
|
+
indices = [member.order_index for member in members]
|
|
34
|
+
if len(indices) != len(set(indices)):
|
|
35
|
+
raise ValueError("member order_index values must be unique")
|
|
36
|
+
if indices != list(range(len(members))):
|
|
37
|
+
raise ValueError("member order_index values must be ordered and contiguous from 0")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class DraftCandidateSetManifest(StrictModel):
|
|
41
|
+
lifecycle: Literal["draft"] = "draft"
|
|
42
|
+
candidate_set_id: NonEmptyString
|
|
43
|
+
candidate_set_version: NonEmptyString
|
|
44
|
+
decision_space_id: NonEmptyString
|
|
45
|
+
members: tuple[CandidateSetMember, ...]
|
|
46
|
+
created_at: datetime
|
|
47
|
+
|
|
48
|
+
_aware_created_at = field_validator("created_at")(require_aware)
|
|
49
|
+
|
|
50
|
+
@model_validator(mode="after")
|
|
51
|
+
def validate_members(self) -> DraftCandidateSetManifest:
|
|
52
|
+
_validate_members(self.members)
|
|
53
|
+
return self
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class SealedCandidateSetManifest(StrictModel):
|
|
57
|
+
lifecycle: Literal["sealed"] = "sealed"
|
|
58
|
+
candidate_set_id: NonEmptyString
|
|
59
|
+
candidate_set_version: NonEmptyString
|
|
60
|
+
decision_space_id: NonEmptyString
|
|
61
|
+
members: tuple[CandidateSetMember, ...]
|
|
62
|
+
eligibility_rule_id: NonEmptyString
|
|
63
|
+
eligibility_rule_version: NonEmptyString
|
|
64
|
+
evidence_eligibility_cutoff_at: datetime
|
|
65
|
+
sealed_at: datetime
|
|
66
|
+
manifest_digest: Digest
|
|
67
|
+
|
|
68
|
+
_aware_cutoff = field_validator("evidence_eligibility_cutoff_at")(require_aware)
|
|
69
|
+
_aware_sealed_at = field_validator("sealed_at")(require_aware)
|
|
70
|
+
|
|
71
|
+
@model_validator(mode="after")
|
|
72
|
+
def validate_members(self) -> SealedCandidateSetManifest:
|
|
73
|
+
_validate_members(self.members)
|
|
74
|
+
return self
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def action_identity_digest(identity: ActionIdentity) -> Digest:
|
|
78
|
+
"""Compute the canonical digest of an action identity."""
|
|
79
|
+
|
|
80
|
+
return canonical_digest(identity)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def candidate_set_manifest_digest(manifest: SealedCandidateSetManifest) -> Digest:
|
|
84
|
+
"""Compute the normative digest payload for a sealed candidate set."""
|
|
85
|
+
|
|
86
|
+
payload = {
|
|
87
|
+
"candidate_set_id": manifest.candidate_set_id,
|
|
88
|
+
"candidate_set_version": manifest.candidate_set_version,
|
|
89
|
+
"decision_space_id": manifest.decision_space_id,
|
|
90
|
+
"members": [
|
|
91
|
+
{
|
|
92
|
+
"order_index": member.order_index,
|
|
93
|
+
"candidate_id": member.candidate_id,
|
|
94
|
+
"action_identity_digest": member.action_identity_digest,
|
|
95
|
+
}
|
|
96
|
+
for member in manifest.members
|
|
97
|
+
],
|
|
98
|
+
"eligibility_rule_id": manifest.eligibility_rule_id,
|
|
99
|
+
"eligibility_rule_version": manifest.eligibility_rule_version,
|
|
100
|
+
"evidence_eligibility_cutoff_at": canonical_timestamp(
|
|
101
|
+
manifest.evidence_eligibility_cutoff_at
|
|
102
|
+
),
|
|
103
|
+
}
|
|
104
|
+
return canonical_digest(payload)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def seal_candidate_set(
|
|
108
|
+
draft: DraftCandidateSetManifest,
|
|
109
|
+
*,
|
|
110
|
+
eligibility_rule_id: str,
|
|
111
|
+
eligibility_rule_version: str,
|
|
112
|
+
evidence_eligibility_cutoff_at: datetime,
|
|
113
|
+
sealed_at: datetime,
|
|
114
|
+
) -> SealedCandidateSetManifest:
|
|
115
|
+
"""Create a new immutable sealed manifest from a validated draft."""
|
|
116
|
+
|
|
117
|
+
provisional = SealedCandidateSetManifest(
|
|
118
|
+
candidate_set_id=draft.candidate_set_id,
|
|
119
|
+
candidate_set_version=draft.candidate_set_version,
|
|
120
|
+
decision_space_id=draft.decision_space_id,
|
|
121
|
+
members=draft.members,
|
|
122
|
+
eligibility_rule_id=eligibility_rule_id,
|
|
123
|
+
eligibility_rule_version=eligibility_rule_version,
|
|
124
|
+
evidence_eligibility_cutoff_at=evidence_eligibility_cutoff_at,
|
|
125
|
+
sealed_at=sealed_at,
|
|
126
|
+
manifest_digest="sha256:" + "0" * 64,
|
|
127
|
+
)
|
|
128
|
+
return SealedCandidateSetManifest(
|
|
129
|
+
candidate_set_id=draft.candidate_set_id,
|
|
130
|
+
candidate_set_version=draft.candidate_set_version,
|
|
131
|
+
decision_space_id=draft.decision_space_id,
|
|
132
|
+
members=draft.members,
|
|
133
|
+
eligibility_rule_id=eligibility_rule_id,
|
|
134
|
+
eligibility_rule_version=eligibility_rule_version,
|
|
135
|
+
evidence_eligibility_cutoff_at=evidence_eligibility_cutoff_at,
|
|
136
|
+
sealed_at=sealed_at,
|
|
137
|
+
manifest_digest=candidate_set_manifest_digest(provisional),
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def verify_candidate_set(manifest: SealedCandidateSetManifest) -> bool:
|
|
142
|
+
"""Verify that a sealed manifest still matches its canonical digest."""
|
|
143
|
+
|
|
144
|
+
expected = candidate_set_manifest_digest(manifest)
|
|
145
|
+
return hmac.compare_digest(manifest.manifest_digest, expected)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Canonical serialization and SHA-256 digests."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import math
|
|
7
|
+
from collections.abc import Mapping, Sequence, Set
|
|
8
|
+
from datetime import UTC, datetime
|
|
9
|
+
from decimal import Decimal
|
|
10
|
+
from typing import Any
|
|
11
|
+
from uuid import UUID
|
|
12
|
+
|
|
13
|
+
import rfc8785
|
|
14
|
+
from pydantic import BaseModel
|
|
15
|
+
|
|
16
|
+
from cyandoor._base import Digest
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def canonical_decimal(value: Decimal) -> str:
|
|
20
|
+
"""Render a Decimal in CyanDoor's canonical plain base-10 form."""
|
|
21
|
+
|
|
22
|
+
if not value.is_finite():
|
|
23
|
+
raise ValueError("Decimal must be finite")
|
|
24
|
+
if value.is_zero():
|
|
25
|
+
return "0"
|
|
26
|
+
rendered = format(value, "f")
|
|
27
|
+
if "." in rendered:
|
|
28
|
+
rendered = rendered.rstrip("0").rstrip(".")
|
|
29
|
+
return rendered
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def canonical_timestamp(value: datetime) -> str:
|
|
33
|
+
"""Render an aware timestamp in UTC with exactly six fractional digits."""
|
|
34
|
+
|
|
35
|
+
if value.tzinfo is None or value.utcoffset() is None:
|
|
36
|
+
raise ValueError("timestamp must be timezone-aware")
|
|
37
|
+
return value.astimezone(UTC).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def canonical_value(value: Any) -> Any:
|
|
41
|
+
"""Convert supported Python values into their canonical JSON representation."""
|
|
42
|
+
|
|
43
|
+
if isinstance(value, BaseModel):
|
|
44
|
+
return canonical_value(value.model_dump(mode="python"))
|
|
45
|
+
if isinstance(value, datetime):
|
|
46
|
+
return canonical_timestamp(value)
|
|
47
|
+
if isinstance(value, Decimal):
|
|
48
|
+
return canonical_decimal(value)
|
|
49
|
+
if isinstance(value, UUID):
|
|
50
|
+
return str(value).lower()
|
|
51
|
+
if isinstance(value, Mapping):
|
|
52
|
+
if not all(isinstance(key, str) for key in value):
|
|
53
|
+
raise TypeError("canonical JSON object keys must be strings")
|
|
54
|
+
return {key: canonical_value(item) for key, item in value.items()}
|
|
55
|
+
if isinstance(value, Set):
|
|
56
|
+
raise TypeError("unordered sets are not valid canonical values")
|
|
57
|
+
if isinstance(value, Sequence) and not isinstance(value, (str, bytes, bytearray)):
|
|
58
|
+
return [canonical_value(item) for item in value]
|
|
59
|
+
if isinstance(value, float) and not math.isfinite(value):
|
|
60
|
+
raise ValueError("float must be finite")
|
|
61
|
+
if value is None or isinstance(value, (str, int, float, bool)):
|
|
62
|
+
return value
|
|
63
|
+
raise TypeError(f"unsupported canonical value: {type(value).__name__}")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def canonical_json_bytes(value: Any) -> bytes:
|
|
67
|
+
"""Serialize a supported value according to RFC 8785/JCS."""
|
|
68
|
+
|
|
69
|
+
return rfc8785.dumps(canonical_value(value))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def canonical_digest(value: Any) -> Digest:
|
|
73
|
+
"""Return a prefixed SHA-256 digest of canonical JSON bytes."""
|
|
74
|
+
|
|
75
|
+
return f"sha256:{hashlib.sha256(canonical_json_bytes(value)).hexdigest()}"
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""Evidence references and explicit provenance states."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from typing import Annotated, Literal
|
|
7
|
+
|
|
8
|
+
from pydantic import Field, field_validator
|
|
9
|
+
|
|
10
|
+
from cyandoor._base import Digest, NamespacedKey, NonEmptyString, StrictModel, require_aware
|
|
11
|
+
from cyandoor.canonical import canonical_json_bytes
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class OTelSpanReference(StrictModel):
|
|
15
|
+
kind: Literal["otel_span"] = "otel_span"
|
|
16
|
+
trace_id: NonEmptyString
|
|
17
|
+
span_id: NonEmptyString
|
|
18
|
+
instrumentation_scope: NonEmptyString
|
|
19
|
+
source_system: NonEmptyString
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class OTelLogReference(StrictModel):
|
|
23
|
+
kind: Literal["otel_log"] = "otel_log"
|
|
24
|
+
trace_id: NonEmptyString
|
|
25
|
+
span_id: NonEmptyString
|
|
26
|
+
log_record_id: NonEmptyString
|
|
27
|
+
source_system: NonEmptyString
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class NativeEventReference(StrictModel):
|
|
31
|
+
kind: Literal["native_event"] = "native_event"
|
|
32
|
+
source_system: NonEmptyString
|
|
33
|
+
source_event_id: NonEmptyString
|
|
34
|
+
source_schema_version: NonEmptyString
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ContentObjectReference(StrictModel):
|
|
38
|
+
kind: Literal["content_object"] = "content_object"
|
|
39
|
+
digest: Digest
|
|
40
|
+
media_type: NonEmptyString
|
|
41
|
+
byte_length: Annotated[int, Field(ge=0)]
|
|
42
|
+
storage_class: NonEmptyString
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
type EvidenceSourceReference = Annotated[
|
|
46
|
+
OTelSpanReference | OTelLogReference | NativeEventReference | ContentObjectReference,
|
|
47
|
+
Field(discriminator="kind"),
|
|
48
|
+
]
|
|
49
|
+
type SourceReferences = Annotated[tuple[EvidenceSourceReference, ...], Field(min_length=1)]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def validate_source_references(
|
|
53
|
+
value: tuple[EvidenceSourceReference, ...],
|
|
54
|
+
) -> tuple[EvidenceSourceReference, ...]:
|
|
55
|
+
"""Require canonical ordering and reject duplicate source references."""
|
|
56
|
+
|
|
57
|
+
serialized = [canonical_json_bytes(reference) for reference in value]
|
|
58
|
+
if len(serialized) != len(set(serialized)):
|
|
59
|
+
raise ValueError("source_refs must be unique")
|
|
60
|
+
if serialized != sorted(serialized):
|
|
61
|
+
raise ValueError("source_refs must be canonically sorted")
|
|
62
|
+
return value
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class ObservedValue[T](StrictModel):
|
|
66
|
+
state: Literal["observed"] = "observed"
|
|
67
|
+
value: T
|
|
68
|
+
source_refs: SourceReferences
|
|
69
|
+
observed_at: datetime
|
|
70
|
+
available_at: datetime
|
|
71
|
+
|
|
72
|
+
_aware_observed_at = field_validator("observed_at")(require_aware)
|
|
73
|
+
_aware_available_at = field_validator("available_at")(require_aware)
|
|
74
|
+
_valid_source_refs = field_validator("source_refs")(validate_source_references)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class DerivedValue[T](StrictModel):
|
|
78
|
+
state: Literal["derived"] = "derived"
|
|
79
|
+
value: T
|
|
80
|
+
derivation_id: NonEmptyString
|
|
81
|
+
derivation_version: NonEmptyString
|
|
82
|
+
source_refs: SourceReferences
|
|
83
|
+
derived_at: datetime
|
|
84
|
+
available_at: datetime
|
|
85
|
+
|
|
86
|
+
_aware_derived_at = field_validator("derived_at")(require_aware)
|
|
87
|
+
_aware_available_at = field_validator("available_at")(require_aware)
|
|
88
|
+
_valid_source_refs = field_validator("source_refs")(validate_source_references)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class InferredValue[T](StrictModel):
|
|
92
|
+
state: Literal["inferred"] = "inferred"
|
|
93
|
+
value: T
|
|
94
|
+
inference_id: NonEmptyString
|
|
95
|
+
inference_version: NonEmptyString
|
|
96
|
+
source_refs: SourceReferences
|
|
97
|
+
inferred_at: datetime
|
|
98
|
+
available_at: datetime
|
|
99
|
+
|
|
100
|
+
_aware_inferred_at = field_validator("inferred_at")(require_aware)
|
|
101
|
+
_aware_available_at = field_validator("available_at")(require_aware)
|
|
102
|
+
_valid_source_refs = field_validator("source_refs")(validate_source_references)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class UnavailableValue(StrictModel):
|
|
106
|
+
state: Literal["unavailable"] = "unavailable"
|
|
107
|
+
reason_code: NamespacedKey
|
|
108
|
+
checked_at: datetime
|
|
109
|
+
source_refs: tuple[EvidenceSourceReference, ...] = ()
|
|
110
|
+
|
|
111
|
+
_aware_checked_at = field_validator("checked_at")(require_aware)
|
|
112
|
+
_valid_source_refs = field_validator("source_refs")(validate_source_references)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class RedactedValue(StrictModel):
|
|
116
|
+
state: Literal["redacted"] = "redacted"
|
|
117
|
+
reason_code: NamespacedKey
|
|
118
|
+
policy_id: NonEmptyString
|
|
119
|
+
policy_version: NonEmptyString
|
|
120
|
+
redacted_at: datetime
|
|
121
|
+
|
|
122
|
+
_aware_redacted_at = field_validator("redacted_at")(require_aware)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class NotApplicableValue(StrictModel):
|
|
126
|
+
state: Literal["not_applicable"] = "not_applicable"
|
|
127
|
+
reason_code: NamespacedKey
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
type EvidenceString = Annotated[
|
|
131
|
+
ObservedValue[str]
|
|
132
|
+
| DerivedValue[str]
|
|
133
|
+
| InferredValue[str]
|
|
134
|
+
| UnavailableValue
|
|
135
|
+
| RedactedValue
|
|
136
|
+
| NotApplicableValue,
|
|
137
|
+
Field(discriminator="state"),
|
|
138
|
+
]
|
|
139
|
+
type EvidenceDigest = Annotated[
|
|
140
|
+
ObservedValue[Digest]
|
|
141
|
+
| DerivedValue[Digest]
|
|
142
|
+
| InferredValue[Digest]
|
|
143
|
+
| UnavailableValue
|
|
144
|
+
| RedactedValue
|
|
145
|
+
| NotApplicableValue,
|
|
146
|
+
Field(discriminator="state"),
|
|
147
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|