swisstip-core 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.
- swisstip_core-0.1.0/LICENSE +202 -0
- swisstip_core-0.1.0/NOTICE +17 -0
- swisstip_core-0.1.0/PKG-INFO +61 -0
- swisstip_core-0.1.0/README.md +38 -0
- swisstip_core-0.1.0/pyproject.toml +52 -0
- swisstip_core-0.1.0/setup.cfg +4 -0
- swisstip_core-0.1.0/src/swisstip/core/__init__.py +6 -0
- swisstip_core-0.1.0/src/swisstip/core/acceptance.py +244 -0
- swisstip_core-0.1.0/src/swisstip/core/contracts.py +429 -0
- swisstip_core-0.1.0/src/swisstip/core/readiness.py +93 -0
- swisstip_core-0.1.0/src/swisstip/core/release.py +190 -0
- swisstip_core-0.1.0/src/swisstip/core/text.py +14 -0
- swisstip_core-0.1.0/src/swisstip/core/validation.py +191 -0
- swisstip_core-0.1.0/src/swisstip/runtime/__init__.py +5 -0
- swisstip_core-0.1.0/src/swisstip/runtime/acceptance.py +139 -0
- swisstip_core-0.1.0/src/swisstip/runtime/search_cli.py +311 -0
- swisstip_core-0.1.0/src/swisstip/runtime/semantic.py +293 -0
- swisstip_core-0.1.0/src/swisstip/runtime/service.py +531 -0
- swisstip_core-0.1.0/src/swisstip_core.egg-info/PKG-INFO +61 -0
- swisstip_core-0.1.0/src/swisstip_core.egg-info/SOURCES.txt +22 -0
- swisstip_core-0.1.0/src/swisstip_core.egg-info/dependency_links.txt +1 -0
- swisstip_core-0.1.0/src/swisstip_core.egg-info/entry_points.txt +2 -0
- swisstip_core-0.1.0/src/swisstip_core.egg-info/requires.txt +1 -0
- swisstip_core-0.1.0/src/swisstip_core.egg-info/top_level.txt +1 -0
|
@@ -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,17 @@
|
|
|
1
|
+
Swiss TIP - Swisscom Trusted Information Platform
|
|
2
|
+
Copyright 2026 The UBS Hackathon 2026 team: Alexander Bobrovsky and contributors
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
The source catalogues under releases/ contain URLs and planning metadata
|
|
7
|
+
only. Any future release bundle that quotes excerpts of official publications
|
|
8
|
+
of the Swiss Confederation, the cantons or municipalities reproduces those
|
|
9
|
+
texts as cited evidence with their source URLs and access times; they remain
|
|
10
|
+
the property of their publishers and are not relicensed under the Apache
|
|
11
|
+
License. Consult the publishers' terms of use before redistributing them.
|
|
12
|
+
|
|
13
|
+
The admin console vendors HTMX 2.0.7
|
|
14
|
+
(apps/admin-console/src/swisstip/admin_console/static/htmx.min.js), which is
|
|
15
|
+
distributed by the htmx authors under the Zero-Clause BSD licence. It is
|
|
16
|
+
included verbatim so the console needs no network access and no JavaScript
|
|
17
|
+
build step.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swisstip-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Swiss TIP knowledge release format, validator and the four tool operations over a release
|
|
5
|
+
Author: Alexander Bobrovsky
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/bobrovsky420/hackathon2026
|
|
8
|
+
Project-URL: Source, https://github.com/bobrovsky420/hackathon2026
|
|
9
|
+
Project-URL: Issues, https://github.com/bobrovsky420/hackathon2026/issues
|
|
10
|
+
Keywords: mcp,grounding,switzerland,knowledge-release
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Requires-Python: >=3.14
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
License-File: NOTICE
|
|
21
|
+
Requires-Dist: pydantic<3,>=2.11
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# swisstip-core
|
|
25
|
+
|
|
26
|
+
**Last update:** 15 September 2026
|
|
27
|
+
|
|
28
|
+
The shared library of Swiss TIP, the grounding MCP server for Swiss public
|
|
29
|
+
information. It ships two modules:
|
|
30
|
+
|
|
31
|
+
- `swisstip.core`: the Pydantic models of the knowledge release format and of
|
|
32
|
+
the four tool contracts, the release validator and the readiness record.
|
|
33
|
+
- `swisstip.runtime`: the four tool operations (`get_coverage`, `search`,
|
|
34
|
+
`resolve`, `get_evidence`) over a validated release, without any transport.
|
|
35
|
+
|
|
36
|
+
Most users install `swisstip-mcp` (the server) or `swisstip-builder` (the
|
|
37
|
+
workstation tools), which depend on this package at the same version.
|
|
38
|
+
|
|
39
|
+
## Use
|
|
40
|
+
|
|
41
|
+
Python 3.14 or newer.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install swisstip-core
|
|
45
|
+
swisstip-validate-release release.json
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from pathlib import Path
|
|
50
|
+
|
|
51
|
+
from swisstip.core.contracts import SearchRequest
|
|
52
|
+
from swisstip.runtime.service import ReleaseService
|
|
53
|
+
|
|
54
|
+
service = ReleaseService.from_file(Path("release.json"))
|
|
55
|
+
print(service.search(SearchRequest(query="Anmeldung Gemeinde Zürich")))
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Knowledge releases are not on PyPI; they are published with the repository's
|
|
59
|
+
GitHub releases.
|
|
60
|
+
|
|
61
|
+
Licence: Apache-2.0.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# swisstip-core
|
|
2
|
+
|
|
3
|
+
**Last update:** 15 September 2026
|
|
4
|
+
|
|
5
|
+
The shared library of Swiss TIP, the grounding MCP server for Swiss public
|
|
6
|
+
information. It ships two modules:
|
|
7
|
+
|
|
8
|
+
- `swisstip.core`: the Pydantic models of the knowledge release format and of
|
|
9
|
+
the four tool contracts, the release validator and the readiness record.
|
|
10
|
+
- `swisstip.runtime`: the four tool operations (`get_coverage`, `search`,
|
|
11
|
+
`resolve`, `get_evidence`) over a validated release, without any transport.
|
|
12
|
+
|
|
13
|
+
Most users install `swisstip-mcp` (the server) or `swisstip-builder` (the
|
|
14
|
+
workstation tools), which depend on this package at the same version.
|
|
15
|
+
|
|
16
|
+
## Use
|
|
17
|
+
|
|
18
|
+
Python 3.14 or newer.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install swisstip-core
|
|
22
|
+
swisstip-validate-release release.json
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
|
|
28
|
+
from swisstip.core.contracts import SearchRequest
|
|
29
|
+
from swisstip.runtime.service import ReleaseService
|
|
30
|
+
|
|
31
|
+
service = ReleaseService.from_file(Path("release.json"))
|
|
32
|
+
print(service.search(SearchRequest(query="Anmeldung Gemeinde Zürich")))
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Knowledge releases are not on PyPI; they are published with the repository's
|
|
36
|
+
GitHub releases.
|
|
37
|
+
|
|
38
|
+
Licence: Apache-2.0.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Generated by scripts/pypi/build_distributions.py; do not edit.
|
|
2
|
+
[build-system]
|
|
3
|
+
requires = [
|
|
4
|
+
"setuptools>=77",
|
|
5
|
+
]
|
|
6
|
+
build-backend = "setuptools.build_meta"
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "swisstip-core"
|
|
10
|
+
version = "0.1.0"
|
|
11
|
+
description = "Swiss TIP knowledge release format, validator and the four tool operations over a release"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.14"
|
|
14
|
+
license = "Apache-2.0"
|
|
15
|
+
license-files = [
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"NOTICE",
|
|
18
|
+
]
|
|
19
|
+
authors = [
|
|
20
|
+
{ name = "Alexander Bobrovsky" },
|
|
21
|
+
]
|
|
22
|
+
keywords = [
|
|
23
|
+
"mcp",
|
|
24
|
+
"grounding",
|
|
25
|
+
"switzerland",
|
|
26
|
+
"knowledge-release",
|
|
27
|
+
]
|
|
28
|
+
classifiers = [
|
|
29
|
+
"Development Status :: 3 - Alpha",
|
|
30
|
+
"Intended Audience :: Developers",
|
|
31
|
+
"Operating System :: OS Independent",
|
|
32
|
+
"Programming Language :: Python :: 3",
|
|
33
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
34
|
+
"Programming Language :: Python :: 3.14",
|
|
35
|
+
]
|
|
36
|
+
dependencies = [
|
|
37
|
+
"pydantic<3,>=2.11",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/bobrovsky420/hackathon2026"
|
|
42
|
+
Source = "https://github.com/bobrovsky420/hackathon2026"
|
|
43
|
+
Issues = "https://github.com/bobrovsky420/hackathon2026/issues"
|
|
44
|
+
|
|
45
|
+
[project.scripts]
|
|
46
|
+
swisstip-validate-release = "swisstip.core.validation:main"
|
|
47
|
+
|
|
48
|
+
[tool.setuptools.packages.find]
|
|
49
|
+
where = [
|
|
50
|
+
"src",
|
|
51
|
+
]
|
|
52
|
+
namespaces = true
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"""The acceptance suite of a pack: `releases/<pack>/acceptance.yaml`.
|
|
2
|
+
|
|
3
|
+
One case per user question, as the acceptance-test documents state it: the
|
|
4
|
+
question as typed, the expected answer and the trap a generic answer falls
|
|
5
|
+
into, for a reader; the tool steps a caller sends, validated against the tool
|
|
6
|
+
contracts so that a case cannot drift from the API; the claims of the
|
|
7
|
+
expected answer, each checked against the facts the release serves and the
|
|
8
|
+
excerpts they cite; and, for the answer-quality check, what a live caller's
|
|
9
|
+
final answer must and must not say. `swisstip.runtime.acceptance` replays a
|
|
10
|
+
suite against a release with no model involved; the OpenCode harness under
|
|
11
|
+
`scripts/test/mock-mcp/` runs the questions through a live model and its
|
|
12
|
+
grades are aggregated into `acceptance-answers.json`, which `answer_verdict`
|
|
13
|
+
reads as gate G5. docs/architecture/acceptance-gate.md describes the gate.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
from datetime import date, datetime
|
|
19
|
+
from typing import Literal
|
|
20
|
+
|
|
21
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
22
|
+
|
|
23
|
+
from .contracts import Jurisdiction, ResolveRequest, SearchRequest, Status
|
|
24
|
+
from .release import sha256_text
|
|
25
|
+
|
|
26
|
+
ACCEPTANCE_SCHEMA_VERSION = "swiss-tip-acceptance/v1"
|
|
27
|
+
ANSWERS_SCHEMA_VERSION = "swiss-tip-acceptance-answers/v1"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Strict(BaseModel):
|
|
31
|
+
model_config = ConfigDict(extra="forbid")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Policy(Strict):
|
|
35
|
+
as_of: date | Literal["snapshot", "today"] = Field(default="snapshot", description=(
|
|
36
|
+
"Applicability date of every resolve step that names none: the release's snapshot date, today, or a date. "
|
|
37
|
+
"The snapshot date makes a suite pass the same way on every day; staleness is a gate of its own."))
|
|
38
|
+
min_runway_days: int = Field(default=14, ge=0, description=(
|
|
39
|
+
"A release is ready only while its stale_from lies at least this many days after the attestation."))
|
|
40
|
+
answer_check: Literal["required", "advisory", "off"] = Field(default="advisory", description=(
|
|
41
|
+
"Whether gate G5, the graded live-caller runs of acceptance-answers.json, blocks readiness (required), is "
|
|
42
|
+
"reported only (advisory) or is not evaluated (off)."))
|
|
43
|
+
answer_repetitions: int = Field(default=3, ge=1, description="Graded sessions a case needs on the release.")
|
|
44
|
+
answer_pass_rate: float = Field(default=0.8, ge=0, le=1, description=(
|
|
45
|
+
"Share of a case's graded sessions that must pass every applicable criterion; the trap must hold in all."))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class AnswerCriteria(Strict):
|
|
49
|
+
"""What the answer-quality check expects of a live caller's final answer to the case's question."""
|
|
50
|
+
|
|
51
|
+
criteria: list[str] = Field(default_factory=list, description="IDs of the general criteria the grader applies.")
|
|
52
|
+
must_mention: dict[str, str] = Field(default_factory=dict, description=(
|
|
53
|
+
"Name to regular expression the final answer must match, case-insensitive."))
|
|
54
|
+
must_not: dict[str, str] = Field(default_factory=dict, description=(
|
|
55
|
+
"Name to regular expression the final answer must not assert (a negated or quoted match does not count)."))
|
|
56
|
+
cites: dict[str, str] = Field(default_factory=dict, description="Name to URL fragment the answer must contain.")
|
|
57
|
+
resolved: list[str | list[str]] = Field(default_factory=list, description=(
|
|
58
|
+
"Concepts the caller must have resolved; a nested list names alternatives."))
|
|
59
|
+
|
|
60
|
+
@model_validator(mode="after")
|
|
61
|
+
def patterns_compile(self) -> "AnswerCriteria":
|
|
62
|
+
for group in (self.must_mention, self.must_not):
|
|
63
|
+
for name, pattern in group.items():
|
|
64
|
+
try:
|
|
65
|
+
re.compile(pattern)
|
|
66
|
+
except re.error as exc:
|
|
67
|
+
raise ValueError(f"pattern {name!r} does not compile: {exc}") from exc
|
|
68
|
+
return self
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class SearchStep(Strict):
|
|
72
|
+
query: str = Field(min_length=1, description="The query as the caller sent it, untranslated.")
|
|
73
|
+
expect_concept: str = Field(description="The concept that must be among the first `within` hits.")
|
|
74
|
+
within: int = Field(default=3, ge=1, le=20)
|
|
75
|
+
|
|
76
|
+
def request(self) -> SearchRequest:
|
|
77
|
+
return SearchRequest(query=self.query, limit=self.within)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class ResolveStep(Strict):
|
|
81
|
+
concept_ids: list[str] = Field(min_length=1)
|
|
82
|
+
jurisdiction: dict[str, str] = Field(default_factory=dict)
|
|
83
|
+
context: dict[str, str] = Field(default_factory=dict)
|
|
84
|
+
as_of: date | None = Field(default=None, description="Overrides the policy date for this step.")
|
|
85
|
+
reviewed_only: bool = False
|
|
86
|
+
expect_status: dict[str, Status] = Field(default_factory=dict, description="Expected status per requested concept.")
|
|
87
|
+
|
|
88
|
+
@model_validator(mode="after")
|
|
89
|
+
def matches_the_contract(self) -> "ResolveStep":
|
|
90
|
+
self.request(date.today()) # every contract rule applies: field names, the concept limit, the jurisdiction codes
|
|
91
|
+
unknown = [concept_id for concept_id in self.expect_status if concept_id not in self.concept_ids]
|
|
92
|
+
if unknown:
|
|
93
|
+
raise ValueError(f"expect_status names concepts the step does not request: {unknown}")
|
|
94
|
+
return self
|
|
95
|
+
|
|
96
|
+
def request(self, as_of: date) -> ResolveRequest:
|
|
97
|
+
return ResolveRequest(concept_ids=self.concept_ids, jurisdiction=Jurisdiction(**self.jurisdiction),
|
|
98
|
+
context=self.context, as_of=self.as_of or as_of, reviewed_only=self.reviewed_only)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class Step(Strict):
|
|
102
|
+
"""One tool call of the case: exactly one of `search` and `resolve`."""
|
|
103
|
+
|
|
104
|
+
search: SearchStep | None = None
|
|
105
|
+
resolve: ResolveStep | None = None
|
|
106
|
+
|
|
107
|
+
@model_validator(mode="after")
|
|
108
|
+
def exactly_one_tool(self) -> "Step":
|
|
109
|
+
if (self.search is None) == (self.resolve is None):
|
|
110
|
+
raise ValueError("a step is either a search or a resolve")
|
|
111
|
+
return self
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class Claim(Strict):
|
|
115
|
+
"""One assertion of the expected answer, checked against a served fact and its cited excerpt."""
|
|
116
|
+
|
|
117
|
+
claim: str = Field(min_length=1, description="The assertion in the reader's words.")
|
|
118
|
+
concept: str = Field(description="The concept whose served facts must carry it.")
|
|
119
|
+
fact_id: str | None = Field(default=None, description="Pins the fact; otherwise any served fact of the concept may hold it.")
|
|
120
|
+
statement_contains: list[str] = Field(default_factory=list, description="Phrases the fact's statement contains.")
|
|
121
|
+
excerpt_contains: list[str] = Field(default_factory=list, description=(
|
|
122
|
+
"Phrases one cited excerpt of that fact contains, verbatim in the language of the source."))
|
|
123
|
+
|
|
124
|
+
@model_validator(mode="after")
|
|
125
|
+
def states_something_checkable(self) -> "Claim":
|
|
126
|
+
if not (self.fact_id or self.statement_contains or self.excerpt_contains):
|
|
127
|
+
raise ValueError(f"claim {self.claim!r} names neither a fact nor a phrase")
|
|
128
|
+
return self
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class Case(Strict):
|
|
132
|
+
case_id: str = Field(min_length=1)
|
|
133
|
+
label: str = Field(min_length=1)
|
|
134
|
+
spec: str | None = Field(default=None, description="Section of the acceptance-test document the case restates.")
|
|
135
|
+
question: str = Field(min_length=1, description="The user's question, verbatim.")
|
|
136
|
+
expected_answer: str = Field(min_length=1)
|
|
137
|
+
trap: str | None = Field(default=None, description="The mistake a generic answer makes.")
|
|
138
|
+
blocking: bool = True
|
|
139
|
+
quarantine_reason: str | None = Field(default=None, description="Why a non-blocking case is kept in the suite.")
|
|
140
|
+
steps: list[Step] = Field(default_factory=list, description=(
|
|
141
|
+
"Tool calls to replay; a case without steps is checked only by the answer-quality check."))
|
|
142
|
+
claims: list[Claim] = Field(default_factory=list)
|
|
143
|
+
not_served: dict[str, list[str]] = Field(default_factory=dict, description=(
|
|
144
|
+
"Per concept, phrases its not_served list must keep naming."))
|
|
145
|
+
must_not_serve: list[str] = Field(default_factory=list, description="Fact IDs no step of the case may return.")
|
|
146
|
+
answer: AnswerCriteria | None = Field(default=None, description=(
|
|
147
|
+
"What the live caller's answer must and must not say; a case without it is not part of gate G5."))
|
|
148
|
+
|
|
149
|
+
@model_validator(mode="after")
|
|
150
|
+
def consistent(self) -> "Case":
|
|
151
|
+
if self.blocking and self.quarantine_reason:
|
|
152
|
+
raise ValueError(f"case {self.case_id} is blocking and has a quarantine reason")
|
|
153
|
+
if not self.blocking and not (self.quarantine_reason or "").strip():
|
|
154
|
+
raise ValueError(f"case {self.case_id} is not blocking and gives no quarantine reason")
|
|
155
|
+
resolved = {concept_id for step in self.steps if step.resolve for concept_id in step.resolve.concept_ids}
|
|
156
|
+
for claim in self.claims:
|
|
157
|
+
if claim.concept not in resolved:
|
|
158
|
+
raise ValueError(f"case {self.case_id}: claim {claim.claim!r} names {claim.concept}, which no resolve step requests")
|
|
159
|
+
for concept_id in self.not_served:
|
|
160
|
+
if concept_id not in resolved:
|
|
161
|
+
raise ValueError(f"case {self.case_id}: not_served names {concept_id}, which no resolve step requests")
|
|
162
|
+
return self
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
class AcceptanceFile(Strict):
|
|
166
|
+
schema_version: Literal["swiss-tip-acceptance/v1"] = ACCEPTANCE_SCHEMA_VERSION
|
|
167
|
+
pack: str
|
|
168
|
+
policy: Policy = Field(default_factory=Policy)
|
|
169
|
+
cases: list[Case] = Field(min_length=1)
|
|
170
|
+
|
|
171
|
+
@model_validator(mode="after")
|
|
172
|
+
def unique_case_ids(self) -> "AcceptanceFile":
|
|
173
|
+
ids = [case.case_id for case in self.cases]
|
|
174
|
+
duplicates = sorted({case_id for case_id in ids if ids.count(case_id) > 1})
|
|
175
|
+
if duplicates:
|
|
176
|
+
raise ValueError(f"duplicate case IDs: {duplicates}")
|
|
177
|
+
return self
|
|
178
|
+
|
|
179
|
+
def case(self, case_id: str) -> Case | None:
|
|
180
|
+
return next((case for case in self.cases if case.case_id == case_id), None)
|
|
181
|
+
|
|
182
|
+
def digest(self) -> str:
|
|
183
|
+
"""SHA-256 over the canonical JSON of the suite: a reformatted or commented YAML keeps it, a changed expectation does not."""
|
|
184
|
+
return sha256_text(json.dumps(self.model_dump(mode="json"), ensure_ascii=False, sort_keys=True, separators=(",", ":")))
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
class AnswerRecord(Strict):
|
|
188
|
+
"""The graded live-caller sessions of one case on one release, as the harness aggregated them."""
|
|
189
|
+
|
|
190
|
+
runs: int = Field(ge=0, description="Answered sessions with the server on this release.")
|
|
191
|
+
graded: int = Field(ge=0)
|
|
192
|
+
trap_held: int = Field(ge=0, description="Graded sessions whose answer avoided the case's trap.")
|
|
193
|
+
criteria_pass: int = Field(ge=0, description="Graded sessions that met every applicable criterion.")
|
|
194
|
+
models: list[str] = Field(default_factory=list)
|
|
195
|
+
unsupported_claims: list[str] = Field(default_factory=list, description="Specifics the graders found unsupported.")
|
|
196
|
+
run_folders: list[str] = Field(default_factory=list)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class AcceptanceAnswers(Strict):
|
|
200
|
+
"""`releases/<pack>/acceptance-answers.json`: the grades of the live-caller runs, bound to a release and a suite."""
|
|
201
|
+
|
|
202
|
+
schema_version: Literal["swiss-tip-acceptance-answers/v1"] = ANSWERS_SCHEMA_VERSION
|
|
203
|
+
pack: str
|
|
204
|
+
release_id: str
|
|
205
|
+
content_sha256: str
|
|
206
|
+
suite_sha256: str
|
|
207
|
+
aggregated_at: datetime
|
|
208
|
+
cases: dict[str, AnswerRecord] = Field(default_factory=dict)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def answer_verdict(suite: AcceptanceFile, answers: AcceptanceAnswers | None, content_sha256: str) -> dict:
|
|
212
|
+
"""Gate G5: whether the graded sessions on this release meet the policy for every blocking case with an answer block.
|
|
213
|
+
|
|
214
|
+
`passed` is true when no case falls short, or when the policy is advisory or off; `detail` says what was found."""
|
|
215
|
+
policy = suite.policy
|
|
216
|
+
checked = [case for case in suite.cases if case.blocking and case.answer is not None]
|
|
217
|
+
if policy.answer_check == "off":
|
|
218
|
+
return dict(passed=True, mode="off", detail="answer check off", cases={})
|
|
219
|
+
if answers is None:
|
|
220
|
+
return dict(passed=policy.answer_check != "required", mode=policy.answer_check,
|
|
221
|
+
detail="no acceptance-answers.json", cases={})
|
|
222
|
+
if answers.content_sha256 != content_sha256 or answers.suite_sha256 != suite.digest():
|
|
223
|
+
return dict(passed=policy.answer_check != "required", mode=policy.answer_check,
|
|
224
|
+
detail="acceptance-answers.json is for another release or suite", cases={})
|
|
225
|
+
cases: dict[str, dict] = {}
|
|
226
|
+
for case in checked:
|
|
227
|
+
record = answers.cases.get(case.case_id)
|
|
228
|
+
if record is None or record.graded == 0:
|
|
229
|
+
cases[case.case_id] = dict(passed=False, reason="no graded session")
|
|
230
|
+
continue
|
|
231
|
+
rate = record.criteria_pass / record.graded
|
|
232
|
+
reasons = []
|
|
233
|
+
if record.graded < policy.answer_repetitions:
|
|
234
|
+
reasons.append(f"{record.graded} of {policy.answer_repetitions} graded sessions")
|
|
235
|
+
if record.trap_held != record.graded:
|
|
236
|
+
reasons.append(f"trap held in {record.trap_held} of {record.graded}")
|
|
237
|
+
if rate < policy.answer_pass_rate:
|
|
238
|
+
reasons.append(f"criteria passed in {record.criteria_pass} of {record.graded}, below {policy.answer_pass_rate:.0%}")
|
|
239
|
+
cases[case.case_id] = dict(passed=not reasons, graded=record.graded, trap_held=record.trap_held,
|
|
240
|
+
criteria_pass=record.criteria_pass, reason="; ".join(reasons))
|
|
241
|
+
failing = [case_id for case_id, verdict in cases.items() if not verdict["passed"]]
|
|
242
|
+
detail = (f"{len(checked) - len(failing)} of {len(checked)} answer-checked case(s) meet the policy"
|
|
243
|
+
+ ("; short: " + ", ".join(f"{case_id} ({cases[case_id]['reason']})" for case_id in failing) if failing else ""))
|
|
244
|
+
return dict(passed=not failing or policy.answer_check == "advisory", mode=policy.answer_check, detail=detail, cases=cases)
|