thea-software 3.53.0__py3-none-any.whl

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.
atlas_cli.py ADDED
@@ -0,0 +1,209 @@
1
+ #!/usr/bin/env python3
2
+ """The installable entry point: resolve WHICH atlas, then run the contract's own CLI against it.
3
+
4
+ A SEPARATE MODULE (2.11.0) because `atlascore` fixes the root at IMPORT time: this resolves it first,
5
+ exports it, then imports the harness. IT PRINTS THE RULE THAT DECIDED THE ROOT: an explicit flag and
6
+ a lucky fall-through are the same answer with very different trust. A CONSUMER PINS A REF, NEVER
7
+ `main`, in `.atlas.yaml`, so the pin is reviewed in its own diff.
8
+ WITH NO ROOT AND NO CHECKOUT (3.53.0) it fetches its own version's release, sha256-checked; else refuses.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import hashlib
14
+ import io
15
+ import os
16
+ import re
17
+ import shutil
18
+ import sys
19
+ import tarfile
20
+ import tempfile
21
+ from pathlib import Path
22
+
23
+ import yaml
24
+
25
+ CONSUMER_CONFIG = ".atlas.yaml"
26
+ FLAG = "--atlas-root"
27
+ RELEASES = "https://github.com/HLIntel/thea-software/releases/download"
28
+ INSTALLED_FROM = "the checkout this entry point was installed from"
29
+ MARKER = ".thea-release.sha256" # written last: an unmarked cache is never used
30
+ # REFUSE RATHER THAN INVENT (3.47.0): a key not known by name is refused at its file:line.
31
+ SECTIONS, PIN = ("atlas", "stack_tiers", "markdown_policy"), ("ref", "root", "task", "change_class", "process")
32
+
33
+
34
+ class ConfigError(ValueError):
35
+ """A root flag or consumer config this entry point refuses to guess about."""
36
+
37
+
38
+ def _keys(path: Path, node, what: str, allowed=()) -> dict:
39
+ if not isinstance(node, yaml.MappingNode):
40
+ raise ConfigError(f"{path}:{node.start_mark.line + 1}: {what} must be a mapping")
41
+ out = {}
42
+ for key, value in node.value:
43
+ name, line = key.value, key.start_mark.line + 1
44
+ if not isinstance(name, str) or name in out or allowed and name not in allowed:
45
+ raise ConfigError(f"{path}:{line}: bad or repeated key {name!r} in {what}; allowed: {allowed}")
46
+ out[name] = value
47
+ return out
48
+
49
+
50
+ def _pin(path: Path) -> dict[str, str]:
51
+ """The `atlas:` mapping of one config file, every key checked by name."""
52
+ try:
53
+ doc = yaml.compose(path.read_text(encoding="utf-8"))
54
+ except yaml.YAMLError as exc:
55
+ mark = getattr(exc, "problem_mark", None)
56
+ raise ConfigError(f"{path}:{mark.line + 1 if mark else 1}: not parseable YAML") from None
57
+ sections = _keys(path, doc, CONSUMER_CONFIG, SECTIONS) if doc else {}
58
+ pins = {name: _keys(path, node, name) for name, node in sections.items()}.get("atlas", {})
59
+ for name, value in pins.items():
60
+ if name not in PIN or value.tag != "tag:yaml.org,2002:str" or not value.value.strip():
61
+ raise ConfigError(f"{path}:{value.start_mark.line + 1}: atlas.{name}: want a string in {PIN}")
62
+ return {name: value.value for name, value in pins.items()}
63
+
64
+
65
+ def _config(start: Path) -> tuple[dict, Path | None]:
66
+ """The pin of the nearest .atlas.yaml at or above `start`; ConfigError on any doubt."""
67
+ for path in (d / CONSUMER_CONFIG for d in [start, *start.parents]):
68
+ if path.exists():
69
+ return _pin(path), path
70
+ return {}, None
71
+
72
+
73
+ def root_flag(argv: list[str]) -> tuple[str | None, int, int]:
74
+ """(value, index, width) of the root flag, or (None, -1, 0); refused with no value (3.47.0)."""
75
+ hits = [i for i, arg in enumerate(argv) if arg == FLAG or arg.startswith(FLAG + "=")]
76
+ if not hits:
77
+ return None, -1, 0
78
+ i, eq = hits[0], argv[hits[0]] != FLAG
79
+ value = argv[i].partition("=")[2] if eq else (argv[i + 1 :] or [""])[0]
80
+ if len(hits) > 1 or not value.strip() or value.startswith("-") and not eq:
81
+ raise ConfigError(f"{FLAG} needs one directory, given once; got {value!r}")
82
+ return value, i, 1 if eq else 2
83
+
84
+
85
+ def resolve_root(argv: list[str], cwd: Path) -> tuple[Path, str]:
86
+ """The atlas this invocation runs against, and the rule that decided it. In declared order."""
87
+ value = root_flag(argv)[0]
88
+ if value is not None:
89
+ return Path(value).expanduser().resolve(), f"explicit {FLAG}"
90
+ for var in ("THEA_ROOT", "CODE_DEVELOPMENT_ROOT"): # the second is the pre-3.0 name, still honoured
91
+ if os.environ.get(var):
92
+ return Path(os.environ[var]).resolve(), f"{var} in the environment"
93
+ config, where = _config(cwd)
94
+ if config.get("root"):
95
+ base = (where.parent / config["root"]).resolve()
96
+ return base, f"root declared in {where.name} (ref {config.get('ref', 'unpinned')})"
97
+ return Path(__file__).resolve().parents[1], INSTALLED_FROM
98
+
99
+
100
+ class FetchError(RuntimeError):
101
+ """A release atlas refused: unreachable, unverified, or another version."""
102
+
103
+
104
+ def _get(url: str) -> bytes:
105
+ import urllib.request # noqa: PLC0415
106
+
107
+ try:
108
+ with urllib.request.urlopen(url, timeout=60) as r: # noqa: S310 — a fixed https base
109
+ return r.read()
110
+ except (OSError, ValueError) as exc:
111
+ raise FetchError(f"cannot download {url}: {exc}") from None
112
+
113
+
114
+ def fetch_atlas(version: str) -> Path:
115
+ """Release v<version>'s tree, cached or downloaded and sha256-checked; else FetchError."""
116
+ dest = Path(os.environ.get("XDG_CACHE_HOME") or Path.home() / ".cache", "thea", f"atlas-{version}")
117
+ if (dest / MARKER).is_file():
118
+ return dest
119
+ name = f"thea-v{version}.tar.gz"
120
+ url = f"{RELEASES}/v{version}/{name}"
121
+ want = re.findall(
122
+ rf"^([0-9a-f]{{64}}) [ *]{re.escape(name)}$", _get(url + ".sha256").decode(errors="replace"), re.M
123
+ )
124
+ blob = _get(url)
125
+ if len(want) != 1 or hashlib.sha256(blob).hexdigest() != want[0]:
126
+ raise FetchError(f"{name}: sha256 is not its release's one digest {want}")
127
+ dest.parent.mkdir(parents=True, exist_ok=True)
128
+ work = Path(tempfile.mkdtemp(dir=dest.parent))
129
+ try:
130
+ with tarfile.open(fileobj=io.BytesIO(blob)) as tar:
131
+ tops = {m.name.split("/")[0] for m in tar}
132
+ tar.extractall(work, filter="data") # refuses absolute, climbing and escaping links
133
+ tree = work / tops.pop()
134
+ if tops or (tree / "VERSION").read_text().strip() != version:
135
+ raise FetchError(f"{name} is not one tree of contract {version}")
136
+ (tree / MARKER).write_text(f"{want[0]} {name}\n")
137
+ shutil.rmtree(dest, ignore_errors=True) # an unmarked, interrupted unpack
138
+ os.replace(tree, dest)
139
+ except (tarfile.TarError, OSError, TypeError) as exc: # TypeError: no data filter before 3.11.4
140
+ raise FetchError(f"{name} could not be unpacked: {exc}") from None
141
+ finally:
142
+ shutil.rmtree(work, ignore_errors=True)
143
+ return dest
144
+
145
+
146
+ def _resolved(argv: list[str]) -> tuple:
147
+ try:
148
+ root, rule = resolve_root(argv, Path.cwd())
149
+ if rule != INSTALLED_FROM or (root / "atlas.yaml").exists():
150
+ return root, rule
151
+ if os.environ.get("THEA_NO_FETCH") == "1":
152
+ return root, rule + "; THEA_NO_FETCH=1"
153
+ from importlib.metadata import version # noqa: PLC0415
154
+
155
+ return fetch_atlas(version("thea-software")), "its own release, sha256-checked"
156
+ except (ConfigError, FetchError, ImportError) as exc:
157
+ print(f"refused: {exc}", file=sys.stderr)
158
+ return None, None
159
+
160
+
161
+ def main(argv: list[str] | None = None) -> int:
162
+ argv = list(sys.argv[1:] if argv is None else argv)
163
+ root, rule = _resolved(argv)
164
+ if root is None:
165
+ return 2
166
+ _, index, width = root_flag(argv)
167
+ del argv[index : index + width]
168
+ if not (root / "atlas.yaml").exists():
169
+ print(f"no atlas at {root} (resolved by: {rule})", file=sys.stderr)
170
+ print(f"point at a checkout with {FLAG}, THEA_ROOT, or `atlas: root:` in {CONSUMER_CONFIG}", file=sys.stderr)
171
+ return 2
172
+ os.environ["THEA_ROOT"] = os.environ["CODE_DEVELOPMENT_ROOT"] = str(root)
173
+ # THE HARNESS COMES FROM THE ATLAS, NEVER THE WHEEL (3.7.0): a bundled copy is a second implementation.
174
+ harness = root / "scripts"
175
+ if not (harness / "atlas.py").exists():
176
+ print(f"{root} has an atlas.yaml and no scripts/atlas.py — not a Thea checkout", file=sys.stderr)
177
+ return 2
178
+ sys.path.insert(0, str(harness))
179
+ if "--where" in argv:
180
+ print(f"atlas root: {root}")
181
+ print(f"resolved by: {rule}")
182
+ # An agent handed only an install must still find where to start: the resolved atlas's entry.
183
+ print(f"agent entry: {root / '.agent' / 'bootstrap.json'} (then: thea gate <file>)")
184
+ return 0
185
+ import atlas # noqa: PLC0415 — deliberate: the root must be exported before this import
186
+
187
+ return atlas.main(argv or ["check"])
188
+
189
+
190
+ def mcp_main() -> int:
191
+ """`thea-mcp`: the same root resolution, then serve the resolved atlas's MCP route on stdio."""
192
+ argv = sys.argv[1:]
193
+ if "--where" in argv:
194
+ return main(argv)
195
+ root, rule = _resolved(argv)
196
+ if root is None:
197
+ return 2
198
+ if not (root / "scripts" / "thea_mcp.py").exists():
199
+ print(f"no Thea MCP server at {root} (resolved by: {rule})", file=sys.stderr)
200
+ return 2
201
+ os.environ["THEA_ROOT"] = os.environ["CODE_DEVELOPMENT_ROOT"] = str(root)
202
+ sys.path.insert(0, str(root / "scripts"))
203
+ import thea_mcp # noqa: PLC0415 — deliberate: the root must be exported before this import
204
+
205
+ return thea_mcp.serve()
206
+
207
+
208
+ if __name__ == "__main__":
209
+ sys.exit(main())
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: thea-software
3
+ Version: 3.53.0
4
+ Summary: Contract harness for Thea, the engineering layer for AI. The atlas is polyglot; only this harness is Python.
5
+ Project-URL: Homepage, https://github.com/HLIntel/thea-software
6
+ Project-URL: Documentation, https://github.com/HLIntel/thea-software/blob/main/llms.txt
7
+ Project-URL: Issues, https://github.com/HLIntel/thea-software/issues
8
+ Project-URL: Source, https://github.com/HLIntel/thea-software
9
+ Project-URL: Agent entry, https://raw.githubusercontent.com/HLIntel/thea-software/main/.agent/bootstrap.json
10
+ Project-URL: LLM instructions, https://raw.githubusercontent.com/HLIntel/thea-software/main/llms.txt
11
+ Project-URL: Changelog, https://github.com/HLIntel/thea-software/blob/main/docs/VERSIONING.md
12
+ Keywords: engineering-atlas,polyglot,contract-verification,ai-agents,mcp,llm,agent-harness,code-verification,developer-tools,static-analysis,supply-chain-security,claude-code,agents-md
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Topic :: Software Development :: Quality Assurance
18
+ Classifier: Topic :: Software Development :: Testing
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Requires-Python: >=3.11
21
+ License-File: LICENSE
22
+ Requires-Dist: pyyaml<7,>=6.0.3
23
+ Provides-Extra: quality
24
+ Requires-Dist: ruff>=0.6; extra == "quality"
25
+ Dynamic: license-file
@@ -0,0 +1,7 @@
1
+ atlas_cli.py,sha256=bO87Q8-pwqMVa69V7Om-eTbZRHBC97ZKNJOUbaO0Yyg,9199
2
+ thea_software-3.53.0.dist-info/licenses/LICENSE,sha256=k-Z5jRt4D0HfDG4warBoDzAKXvlsPmUVDftQNOP8lGQ,1068
3
+ thea_software-3.53.0.dist-info/METADATA,sha256=CVb2fR-AkbOjItWTwO_Dh09ob7zSh9yHzzNimUYxnIY,1490
4
+ thea_software-3.53.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
5
+ thea_software-3.53.0.dist-info/entry_points.txt,sha256=m668gdFB9_oPFNwUciaW9TSF8nm1y7sJ319YTHxmLjM,93
6
+ thea_software-3.53.0.dist-info/top_level.txt,sha256=Bp6WGrJWR4VZKKynPsLldtAZknrfgG843JCdrumGazg,10
7
+ thea_software-3.53.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+ atlas = atlas_cli:main
3
+ thea = atlas_cli:main
4
+ thea-mcp = atlas_cli:mcp_main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 HLIntel LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ atlas_cli