forgeproof-cli 0.2.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.
- forge_gate/__init__.py +44 -0
- forge_gate/_deprecated_cli.py +16 -0
- forgeproof/__init__.py +3 -0
- forgeproof/catalog.py +110 -0
- forgeproof/cli.py +560 -0
- forgeproof/config.py +339 -0
- forgeproof/data/gate_catalog.json +66 -0
- forgeproof/data/host_sets.json +7 -0
- forgeproof/debug_caller.py +271 -0
- forgeproof/debug_core.py +368 -0
- forgeproof/fixture_engine.py +81 -0
- forgeproof/fixtures/__init__.py +19 -0
- forgeproof/fixtures/decision_tree_id3.py +90 -0
- forgeproof/fixtures/gradient_descent_momentum.py +73 -0
- forgeproof/fixtures/kmeans_clustering.py +98 -0
- forgeproof/fixtures/knn_classifier.py +79 -0
- forgeproof/fixtures/linear_regression_gd.py +77 -0
- forgeproof/fixtures/logistic_regression.py +85 -0
- forgeproof/fixtures/naive_bayes_text.py +114 -0
- forgeproof/fixtures/perceptron.py +84 -0
- forgeproof/fixtures/polynomial_regression.py +67 -0
- forgeproof/fixtures/ridge_regression_normal_eq.py +75 -0
- forgeproof/ledger.py +633 -0
- forgeproof/lens_tools/__init__.py +11 -0
- forgeproof/lens_tools/guard_lens.py +1250 -0
- forgeproof/lens_tools/invariant_contracts/linear_regression_gd.json +74 -0
- forgeproof/lens_tools/invariant_contracts/polynomial_regression.json +86 -0
- forgeproof/lens_tools/invariant_contracts/ridge_regression_normal_eq.json +86 -0
- forgeproof/lens_tools/invariant_gate.py +199 -0
- forgeproof/lens_tools/metamorphic/__init__.py +9 -0
- forgeproof/lens_tools/metamorphic/relations.py +962 -0
- forgeproof/lens_tools/metamorphic/runner.py +112 -0
- forgeproof/lens_tools/twin_consensus.py +395 -0
- forgeproof/lenses.py +923 -0
- forgeproof/paths.py +56 -0
- forgeproof/reference/ORIGIN.md +29 -0
- forgeproof/reference/decision_tree_id3.py +197 -0
- forgeproof/reference/gradient_descent_momentum.py +141 -0
- forgeproof/reference/kmeans_clustering.py +139 -0
- forgeproof/reference/knn_classifier.py +118 -0
- forgeproof/reference/linear_regression_gd.py +106 -0
- forgeproof/reference/logistic_regression.py +141 -0
- forgeproof/reference/naive_bayes_text.py +152 -0
- forgeproof/reference/perceptron.py +123 -0
- forgeproof/reference/polynomial_regression.py +125 -0
- forgeproof/reference/ridge_regression_normal_eq.py +165 -0
- forgeproof/runner.py +147 -0
- forgeproof/scout/__init__.py +7 -0
- forgeproof/scout/behaviour.py +365 -0
- forgeproof/scout/box.py +581 -0
- forgeproof/scout/cards.py +180 -0
- forgeproof/scout/contract.py +37 -0
- forgeproof/scout/corpus.py +104 -0
- forgeproof/scout/embed.py +217 -0
- forgeproof/scout/engines/__init__.py +1 -0
- forgeproof/scout/engines/chaos.py +454 -0
- forgeproof/scout/engines/chaos_port.py +1331 -0
- forgeproof/scout/engines/chaos_runner.py +178 -0
- forgeproof/scout/engines/executor_port.py +239 -0
- forgeproof/scout/envfit.py +54 -0
- forgeproof/scout/experience.py +161 -0
- forgeproof/scout/fetchproxy.py +368 -0
- forgeproof/scout/ghcache.py +395 -0
- forgeproof/scout/ghpool.py +253 -0
- forgeproof/scout/ghsearch.py +248 -0
- forgeproof/scout/ids.py +82 -0
- forgeproof/scout/intent_lens.py +170 -0
- forgeproof/scout/learn.py +583 -0
- forgeproof/scout/meaning_lens.py +231 -0
- forgeproof/scout/outcomes.py +42 -0
- forgeproof/scout/plant.py +327 -0
- forgeproof/scout/ratify.py +214 -0
- forgeproof/scout/report.py +448 -0
- forgeproof/scout/rule2.py +177 -0
- forgeproof/scout/shape.py +107 -0
- forgeproof/scout/shape_lens.py +71 -0
- forgeproof/scout/signature.py +52 -0
- forgeproof/scout/slots.py +39 -0
- forgeproof/scout/upstream_facts.py +536 -0
- forgeproof/unsupported.py +83 -0
- forgeproof/verifier.py +208 -0
- forgeproof/view_coverage.py +166 -0
- forgeproof_cli-0.2.0.dist-info/METADATA +285 -0
- forgeproof_cli-0.2.0.dist-info/RECORD +89 -0
- forgeproof_cli-0.2.0.dist-info/WHEEL +5 -0
- forgeproof_cli-0.2.0.dist-info/entry_points.txt +3 -0
- forgeproof_cli-0.2.0.dist-info/licenses/LICENSE +201 -0
- forgeproof_cli-0.2.0.dist-info/licenses/NOTICE +23 -0
- forgeproof_cli-0.2.0.dist-info/top_level.txt +2 -0
forgeproof/config.py
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"""Every route out of ForgeProof, in one place (project standard v0.3, build step 1).
|
|
2
|
+
|
|
3
|
+
Each key resolves as: environment variable > ``config.toml`` ``[paths]`` > in-project
|
|
4
|
+
default. A route into ANOTHER project has no default: when it is unset, the caller
|
|
5
|
+
gets :class:`NotConfigured`, whose message names the key and where to set it.
|
|
6
|
+
|
|
7
|
+
Where ``config.toml`` is looked for, first hit wins:
|
|
8
|
+
|
|
9
|
+
1. ``$FORGE_GATE_CONFIG`` (a file path);
|
|
10
|
+
2. ``$FORGE_GATE_HOME/config.toml``;
|
|
11
|
+
3. ``<checkout>/config.toml`` when this file sits in a source checkout
|
|
12
|
+
(``pyproject.toml`` and ``src/forgeproof`` next to each other).
|
|
13
|
+
|
|
14
|
+
``config.toml`` is per host and is not tracked; ``config.example.toml`` lists every key.
|
|
15
|
+
A relative value is taken from the directory that holds ``config.toml``.
|
|
16
|
+
|
|
17
|
+
Keys (classed as the standard's §2 asks):
|
|
18
|
+
|
|
19
|
+
========================= ============== =========================================
|
|
20
|
+
key class default
|
|
21
|
+
========================= ============== =========================================
|
|
22
|
+
FORGE_GATE_HOME in-project the source checkout, else none
|
|
23
|
+
FORGE_GATE_LIBRARY_DIR other project NONE: unset fails, naming the key
|
|
24
|
+
FORGE_GATE_NODE/BUN/QJS host binary ``shutil.which`` (PATH), else BLIND
|
|
25
|
+
FORGE_GATE_SCRATCH in-project ``<home>/tmp`` (created on demand), else the system temp dir
|
|
26
|
+
FORGE_GATE_PYTHON host binary ``sys.executable`` (the interpreter running ForgeProof)
|
|
27
|
+
FORGE_GATE_CORPUS_EXPORT_DIR other project NONE: unset fails, naming the key
|
|
28
|
+
FORGE_GATE_BRAIN_DATA other project NONE: the Brain's data folder (``learn`` appends to scout_registry*.jsonl there)
|
|
29
|
+
FORGE_GATE_SCOUT_DIR runtime state NONE: scout's state folder (report cards, learn lock)
|
|
30
|
+
FORGE_GATE_REGISTRY_BUILD_LOCK other project NONE: the lock file the registry build holds
|
|
31
|
+
FORGE_GATE_LEDGER_DIR runtime state NONE: the exposure + outcome ledgers (step 8a); unset = ledgers OFF
|
|
32
|
+
FORGE_GATE_SCOUT_LIST_DIR in-project ``<checkout>/scout`` (signed list + allowed_signers), else unset fails, naming the key
|
|
33
|
+
========================= ============== =========================================
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
from __future__ import annotations
|
|
37
|
+
|
|
38
|
+
import os
|
|
39
|
+
import shutil
|
|
40
|
+
import sys
|
|
41
|
+
from pathlib import Path
|
|
42
|
+
from typing import Optional
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
import tomllib
|
|
46
|
+
except ModuleNotFoundError: # Python < 3.11: tomli is the same parser
|
|
47
|
+
try:
|
|
48
|
+
import tomli as tomllib # type: ignore[no-redef]
|
|
49
|
+
except ModuleNotFoundError:
|
|
50
|
+
tomllib = None # type: ignore[assignment]
|
|
51
|
+
|
|
52
|
+
CODE: Path = Path(__file__).resolve().parents[2] # src/forgeproof/config.py -> checkout root
|
|
53
|
+
|
|
54
|
+
LIBRARY_KEY = "FORGE_GATE_LIBRARY_DIR"
|
|
55
|
+
CORPUS_KEY = "FORGE_GATE_CORPUS_EXPORT_DIR"
|
|
56
|
+
# `forgeproof learn` (design §4.5, build step 6b-1). None of the three has a default: each is a
|
|
57
|
+
# route into another project's live state (or scout's own), and a guessed path there writes
|
|
58
|
+
# the wrong registry or locks a file nobody else locks.
|
|
59
|
+
BRAIN_DATA_KEY = "FORGE_GATE_BRAIN_DATA"
|
|
60
|
+
SCOUT_DIR_KEY = "FORGE_GATE_SCOUT_DIR"
|
|
61
|
+
BUILD_LOCK_KEY = "FORGE_GATE_REGISTRY_BUILD_LOCK"
|
|
62
|
+
LEARN_KEYS = (BRAIN_DATA_KEY, SCOUT_DIR_KEY, BUILD_LOCK_KEY)
|
|
63
|
+
# The ledgers (design §4a.5, build step 8a, DECISIONS-8a G1). No default: unset means the
|
|
64
|
+
# ledgers are switched OFF and nothing is recorded; setting it is the switch-on.
|
|
65
|
+
LEDGER_KEY = "FORGE_GATE_LEDGER_DIR"
|
|
66
|
+
# Build step 8b (DECISIONS-8b H1, H4): the local embedder for the meaning and intent lenses, and its
|
|
67
|
+
# vector cache. Both unset = those lenses are BLIND(not-configured).
|
|
68
|
+
EMBED_URL_KEY = "FORGE_GATE_EMBED_URL"
|
|
69
|
+
EMBED_CACHE_KEY = "FORGE_GATE_EMBED_CACHE_DIR"
|
|
70
|
+
# KD-13 (f), GitHub-lane loop S1: the folder holding the signed list ``trusted_repos.jsonl`` and
|
|
71
|
+
# ``allowed_signers``. Default: ``scout/`` of the source checkout this file sits in. An installed
|
|
72
|
+
# ForgeProof has no checkout, so it must be told; it never guesses (same shape as KD-2).
|
|
73
|
+
SCOUT_LIST_DIR_KEY = "FORGE_GATE_SCOUT_LIST_DIR"
|
|
74
|
+
LOOPBACK = ("127.0.0.1", "::1") # literal addresses only: a name goes through /etc/hosts (s1 review F3)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class NotConfigured(RuntimeError):
|
|
78
|
+
"""A route out of the project is needed and nobody set it."""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _is_checkout(p: Path) -> bool:
|
|
82
|
+
return (p / "pyproject.toml").is_file() and (p / "src" / "forgeproof").is_dir()
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def home() -> Optional[Path]:
|
|
86
|
+
"""The project folder: $FORGE_GATE_HOME, else the checkout this file sits in, else None.
|
|
87
|
+
|
|
88
|
+
A non-editable install puts this file in site-packages, where parents[2] is
|
|
89
|
+
lib/pythonX.Y; that is NOT a project home, so it is refused rather than guessed.
|
|
90
|
+
"""
|
|
91
|
+
raw = os.environ.get("FORGE_GATE_HOME", "")
|
|
92
|
+
if raw:
|
|
93
|
+
return Path(raw).expanduser()
|
|
94
|
+
return CODE if _is_checkout(CODE) else None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def config_file() -> Optional[Path]:
|
|
98
|
+
raw = os.environ.get("FORGE_GATE_CONFIG", "")
|
|
99
|
+
if raw:
|
|
100
|
+
return Path(raw).expanduser()
|
|
101
|
+
h = home()
|
|
102
|
+
return h / "config.toml" if h is not None else None
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _load() -> dict:
|
|
106
|
+
cf = config_file()
|
|
107
|
+
if cf is None or not cf.is_file():
|
|
108
|
+
return {}
|
|
109
|
+
if tomllib is None:
|
|
110
|
+
raise NotConfigured(
|
|
111
|
+
f"config: {cf} exists but this Python has no TOML parser "
|
|
112
|
+
"(needs 3.11+, or: pip install 'tomli>=2')"
|
|
113
|
+
)
|
|
114
|
+
with cf.open("rb") as fh:
|
|
115
|
+
return tomllib.load(fh).get("paths", {})
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def configured(name: str) -> Optional[str]:
|
|
119
|
+
"""The raw value of ``name`` from the environment or config.toml, else None.
|
|
120
|
+
|
|
121
|
+
Read on every call (not cached at import), so a test or a caller that sets the
|
|
122
|
+
environment after import is seen.
|
|
123
|
+
"""
|
|
124
|
+
raw = os.environ.get(name, "")
|
|
125
|
+
if raw:
|
|
126
|
+
return raw
|
|
127
|
+
raw = str(_load().get(name, "") or "")
|
|
128
|
+
return raw or None
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _as_path(raw: str) -> Path:
|
|
132
|
+
p = Path(raw).expanduser()
|
|
133
|
+
if p.is_absolute():
|
|
134
|
+
return p
|
|
135
|
+
cf = config_file()
|
|
136
|
+
base = cf.parent if cf is not None else Path.cwd()
|
|
137
|
+
return base / p
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def where() -> str:
|
|
141
|
+
"""One line for error messages and the route check: host, config file, CODE."""
|
|
142
|
+
import socket
|
|
143
|
+
|
|
144
|
+
return f"host={socket.gethostname()} config={config_file()} CODE={CODE}"
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def library_dir() -> Path:
|
|
148
|
+
"""The AURA pattern library checkout. No default: it is another project."""
|
|
149
|
+
raw = configured(LIBRARY_KEY)
|
|
150
|
+
if raw is None:
|
|
151
|
+
raise NotConfigured(
|
|
152
|
+
f"{LIBRARY_KEY} is not set. Set it in the environment or in config.toml "
|
|
153
|
+
f"[paths] to a checkout of aura-pattern-library ({where()}). "
|
|
154
|
+
"Only the --live tier and the library tools need it; `forgeproof verify` does not."
|
|
155
|
+
)
|
|
156
|
+
p = _as_path(raw)
|
|
157
|
+
if not p.is_dir():
|
|
158
|
+
raise NotConfigured(f"{LIBRARY_KEY}={p} is not a directory ({where()})")
|
|
159
|
+
return p
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def corpus_export_dir() -> Path:
|
|
163
|
+
"""The aura-code-corpus export root (holds ``<run_id>/`` folders, schema
|
|
164
|
+
code-corpus-export/v1). No default: it is another project's output (design §12.4)."""
|
|
165
|
+
raw = configured(CORPUS_KEY)
|
|
166
|
+
if raw is None:
|
|
167
|
+
raise NotConfigured(
|
|
168
|
+
f"{CORPUS_KEY} is not set. Set it in the environment or in config.toml [paths] "
|
|
169
|
+
f"to the corpus export root, the folder holding <run_id>/ exports ({where()}). "
|
|
170
|
+
"Only `forgeproof scout` needs it."
|
|
171
|
+
)
|
|
172
|
+
p = _as_path(raw)
|
|
173
|
+
if not p.is_dir():
|
|
174
|
+
raise NotConfigured(f"{CORPUS_KEY}={p} is not a directory ({where()})")
|
|
175
|
+
return p
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def brain_data() -> Path:
|
|
179
|
+
"""The Brain's data folder: its ``paths.DATA`` (deploy host:
|
|
180
|
+
``/home/me/Projects/aura-brain/data``). ``learn`` appends to scout's own ladder files there
|
|
181
|
+
(``scout_registry*.jsonl``, 6E's decision A, 2026-11-13) and reads the real ladders for its
|
|
182
|
+
duplicate check. No default. It must be an existing folder holding ``logic_registry.jsonl``:
|
|
183
|
+
a typo, or the Brain's checkout root instead of its data folder, would otherwise pass."""
|
|
184
|
+
raw = configured(BRAIN_DATA_KEY)
|
|
185
|
+
if raw is None:
|
|
186
|
+
raise NotConfigured(
|
|
187
|
+
f"{BRAIN_DATA_KEY} is not set. Set it in the environment or in config.toml [paths] "
|
|
188
|
+
f"to the Brain's data folder ({where()}). Only `forgeproof learn` needs it.")
|
|
189
|
+
p = _as_path(raw)
|
|
190
|
+
if not p.is_dir():
|
|
191
|
+
raise NotConfigured(f"{BRAIN_DATA_KEY}={p} is not an existing directory ({where()})")
|
|
192
|
+
if not (p / "logic_registry.jsonl").is_file():
|
|
193
|
+
raise NotConfigured(f"{BRAIN_DATA_KEY}={p} holds no logic_registry.jsonl: not the Brain's "
|
|
194
|
+
f"data folder ({where()})")
|
|
195
|
+
return p
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def scout_dir() -> Path:
|
|
199
|
+
"""Scout's runtime state folder (design §4.5): report cards, ``scout_learn.lock``. Never in
|
|
200
|
+
git. No default, and it must already exist (a typo would otherwise create a folder the
|
|
201
|
+
registry build never reads)."""
|
|
202
|
+
raw = configured(SCOUT_DIR_KEY)
|
|
203
|
+
if raw is None:
|
|
204
|
+
raise NotConfigured(
|
|
205
|
+
f"{SCOUT_DIR_KEY} is not set. Set it in the environment or in config.toml [paths] "
|
|
206
|
+
f"to scout's state folder ({where()}). Only `forgeproof learn` needs it.")
|
|
207
|
+
p = _as_path(raw)
|
|
208
|
+
if not p.is_dir():
|
|
209
|
+
raise NotConfigured(f"{SCOUT_DIR_KEY}={p} is not an existing directory ({where()})")
|
|
210
|
+
return p
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def ledger_dir() -> Path:
|
|
214
|
+
"""The ledgers' folder (``exposure.jsonl``, ``outcome.jsonl``, ``ledger.lock``; standard §4
|
|
215
|
+
``data/ledgers/``, not in git). No default, and it must already exist: the switch-on creates
|
|
216
|
+
it and its files with their owner and ACL, never a writer."""
|
|
217
|
+
raw = configured(LEDGER_KEY)
|
|
218
|
+
if raw is None:
|
|
219
|
+
raise NotConfigured(
|
|
220
|
+
f"{LEDGER_KEY} is not set: the ledgers are off. Set it in the environment or in "
|
|
221
|
+
f"config.toml [paths] to the ledger folder ({where()}).")
|
|
222
|
+
p = _as_path(raw)
|
|
223
|
+
if not p.is_dir():
|
|
224
|
+
raise NotConfigured(f"{LEDGER_KEY}={p} is not an existing directory ({where()})")
|
|
225
|
+
return p
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def scout_list_dir() -> Path:
|
|
229
|
+
"""The folder holding ``trusted_repos.jsonl`` and ``allowed_signers`` (KD-13 f).
|
|
230
|
+
|
|
231
|
+
``$FORGE_GATE_SCOUT_LIST_DIR`` / config.toml first; else ``<checkout>/scout`` when this file
|
|
232
|
+
sits in a source checkout; else NotConfigured naming the key. It must be an existing folder:
|
|
233
|
+
a typo would otherwise read as "no repo is ratified", which looks like a quiet BLIND."""
|
|
234
|
+
raw = configured(SCOUT_LIST_DIR_KEY)
|
|
235
|
+
if raw is not None:
|
|
236
|
+
p = _as_path(raw)
|
|
237
|
+
elif _is_checkout(CODE):
|
|
238
|
+
p = CODE / "scout"
|
|
239
|
+
else:
|
|
240
|
+
raise NotConfigured(
|
|
241
|
+
f"{SCOUT_LIST_DIR_KEY} is not set and ForgeProof is not running from a source checkout. "
|
|
242
|
+
f"Set it in the environment or in config.toml [paths] to the folder holding "
|
|
243
|
+
f"trusted_repos.jsonl and allowed_signers ({where()}).")
|
|
244
|
+
if not p.is_dir():
|
|
245
|
+
raise NotConfigured(f"{SCOUT_LIST_DIR_KEY}={p} is not an existing directory ({where()})")
|
|
246
|
+
return p
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def embed_url() -> str:
|
|
250
|
+
"""The local embedder's base URL: plain http on a loopback address with a port, nothing else
|
|
251
|
+
(DECISIONS-8b H1: private corpus text never leaves the host). No default."""
|
|
252
|
+
raw = configured(EMBED_URL_KEY)
|
|
253
|
+
if raw is None:
|
|
254
|
+
raise NotConfigured(f"{EMBED_URL_KEY} is not set: the meaning and intent lenses are off "
|
|
255
|
+
f"({where()})")
|
|
256
|
+
return loopback_url(raw)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def loopback_url(raw: str) -> str:
|
|
260
|
+
"""``raw`` if it is http://<literal loopback address>:<port> and nothing more, else NotConfigured."""
|
|
261
|
+
from urllib.parse import urlsplit
|
|
262
|
+
try:
|
|
263
|
+
u = urlsplit(raw)
|
|
264
|
+
port = u.port
|
|
265
|
+
except ValueError as e:
|
|
266
|
+
raise NotConfigured(f"{EMBED_URL_KEY}={raw!r} is not a URL: {e}") from None
|
|
267
|
+
if (u.scheme != "http" or u.hostname not in LOOPBACK or port is None or u.username or u.password
|
|
268
|
+
or u.path not in ("", "/") or u.query or u.fragment):
|
|
269
|
+
raise NotConfigured(f"{EMBED_URL_KEY}={raw!r} must be http://<loopback>:<port> "
|
|
270
|
+
f"(one of {', '.join(LOOPBACK)}), nothing more")
|
|
271
|
+
return raw.rstrip("/")
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def embed_cache_dir() -> Path:
|
|
275
|
+
"""The embedder's vector cache folder (runtime state, not in git). No default; it must exist."""
|
|
276
|
+
raw = configured(EMBED_CACHE_KEY)
|
|
277
|
+
if raw is None:
|
|
278
|
+
raise NotConfigured(f"{EMBED_CACHE_KEY} is not set: no vector cache ({where()})")
|
|
279
|
+
p = _as_path(raw)
|
|
280
|
+
if not p.is_dir():
|
|
281
|
+
raise NotConfigured(f"{EMBED_CACHE_KEY}={p} is not an existing directory ({where()})")
|
|
282
|
+
return p
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def registry_build_lock() -> Path:
|
|
286
|
+
"""The lock file the registry build holds while it rewrites the registry (the maintainer L1,
|
|
287
|
+
2026-11-13). On the deploy host: the file bu's hourly ``flock -n`` names. No default, and it
|
|
288
|
+
must already exist: a lock file learn created itself would be one the build never takes,
|
|
289
|
+
so holding it would protect nothing."""
|
|
290
|
+
raw = configured(BUILD_LOCK_KEY)
|
|
291
|
+
if raw is None:
|
|
292
|
+
raise NotConfigured(
|
|
293
|
+
f"{BUILD_LOCK_KEY} is not set. Set it in the environment or in config.toml [paths] "
|
|
294
|
+
f"to the lock file the registry build holds ({where()}). Only `forgeproof learn` needs it.")
|
|
295
|
+
p = _as_path(raw)
|
|
296
|
+
if not p.is_file():
|
|
297
|
+
raise NotConfigured(
|
|
298
|
+
f"{BUILD_LOCK_KEY}={p} does not exist. learn never creates it: it must be the file "
|
|
299
|
+
f"the registry build locks ({where()})")
|
|
300
|
+
return p
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def scratch_dir() -> Path:
|
|
304
|
+
"""Where lenses write short-lived child scripts. Created on demand.
|
|
305
|
+
|
|
306
|
+
Before build step 1 the determinism lens wrote into ``<checkout>/tmp`` and relied on
|
|
307
|
+
that folder already existing: true on the deploy host, false in a fresh clone or an
|
|
308
|
+
install, where the lens went ERROR (measured 2026-11-11).
|
|
309
|
+
"""
|
|
310
|
+
import tempfile
|
|
311
|
+
|
|
312
|
+
raw = configured("FORGE_GATE_SCRATCH")
|
|
313
|
+
if raw:
|
|
314
|
+
d = _as_path(raw)
|
|
315
|
+
else:
|
|
316
|
+
h = home()
|
|
317
|
+
d = h / "tmp" if h is not None else Path(tempfile.gettempdir()) / "forgeproof"
|
|
318
|
+
d.mkdir(parents=True, exist_ok=True)
|
|
319
|
+
return d
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def python() -> str:
|
|
323
|
+
"""The interpreter for child runs (oracles, fixtures, mutants).
|
|
324
|
+
|
|
325
|
+
Default: the interpreter running ForgeProof, which satisfies ``requires-python``.
|
|
326
|
+
Not ``python3`` from PATH: on the dev machine that was Xcode's 3.9.6, which rejects
|
|
327
|
+
the reference files' zero-width characters, and 7 of 10 patterns read as UNSTABLE
|
|
328
|
+
(measured 2026-11-11, build step 1).
|
|
329
|
+
"""
|
|
330
|
+
raw = configured("FORGE_GATE_PYTHON")
|
|
331
|
+
return str(_as_path(raw)) if raw else sys.executable
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def engine(name: str) -> Optional[str]:
|
|
335
|
+
"""A JavaScript engine binary: FORGE_GATE_<NAME> > PATH > None (the caller goes BLIND)."""
|
|
336
|
+
raw = configured("FORGE_GATE_" + name.upper())
|
|
337
|
+
if raw:
|
|
338
|
+
return str(_as_path(raw))
|
|
339
|
+
return shutil.which(name)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.1.0",
|
|
3
|
+
"reference_origin": "forgeproof/reference/ORIGIN.md (library commit c39c1dcc3adb0aa9bd04eb30f1f00045c14c88ce)",
|
|
4
|
+
"patterns": {
|
|
5
|
+
"kmeans_clustering": {
|
|
6
|
+
"aura_path": "python/data-science/core_ml/kmeans_clustering.py",
|
|
7
|
+
"fixture": "kmeans_clustering",
|
|
8
|
+
"category": "core_ml",
|
|
9
|
+
"description": "k-Means clustering with seed-locked synthetic data."
|
|
10
|
+
},
|
|
11
|
+
"linear_regression_gd": {
|
|
12
|
+
"aura_path": "python/data-science/core_ml/linear_regression_gd.py",
|
|
13
|
+
"fixture": "linear_regression_gd",
|
|
14
|
+
"category": "core_ml",
|
|
15
|
+
"description": "Linear regression via batch gradient descent."
|
|
16
|
+
},
|
|
17
|
+
"knn_classifier": {
|
|
18
|
+
"aura_path": "python/data-science/core_ml/knn_classifier.py",
|
|
19
|
+
"fixture": "knn_classifier",
|
|
20
|
+
"category": "core_ml",
|
|
21
|
+
"description": "k-nearest neighbors classifier."
|
|
22
|
+
},
|
|
23
|
+
"logistic_regression": {
|
|
24
|
+
"aura_path": "python/data-science/core_ml/logistic_regression.py",
|
|
25
|
+
"fixture": "logistic_regression",
|
|
26
|
+
"category": "core_ml",
|
|
27
|
+
"description": "Binary logistic regression via gradient descent."
|
|
28
|
+
},
|
|
29
|
+
"naive_bayes_text": {
|
|
30
|
+
"aura_path": "python/data-science/core_ml/naive_bayes_text.py",
|
|
31
|
+
"fixture": "naive_bayes_text",
|
|
32
|
+
"category": "core_ml",
|
|
33
|
+
"description": "Multinomial Naive Bayes for text classification."
|
|
34
|
+
},
|
|
35
|
+
"polynomial_regression": {
|
|
36
|
+
"aura_path": "python/data-science/statistical_modeling/polynomial_regression.py",
|
|
37
|
+
"fixture": "polynomial_regression",
|
|
38
|
+
"category": "statistical_modeling",
|
|
39
|
+
"description": "Polynomial regression via Vandermonde least squares."
|
|
40
|
+
},
|
|
41
|
+
"decision_tree_id3": {
|
|
42
|
+
"aura_path": "python/data-science/core_ml/decision_tree_id3.py",
|
|
43
|
+
"fixture": "decision_tree_id3",
|
|
44
|
+
"category": "core_ml",
|
|
45
|
+
"description": "ID3 decision tree for categorical features."
|
|
46
|
+
},
|
|
47
|
+
"perceptron": {
|
|
48
|
+
"aura_path": "python/data-science/core_ml/perceptron.py",
|
|
49
|
+
"fixture": "perceptron",
|
|
50
|
+
"category": "core_ml",
|
|
51
|
+
"description": "Perceptron learning algorithm."
|
|
52
|
+
},
|
|
53
|
+
"ridge_regression_normal_eq": {
|
|
54
|
+
"aura_path": "python/data-science/core_ml/ridge_regression_normal_eq.py",
|
|
55
|
+
"fixture": "ridge_regression_normal_eq",
|
|
56
|
+
"category": "core_ml",
|
|
57
|
+
"description": "Ridge regression via normal equations."
|
|
58
|
+
},
|
|
59
|
+
"gradient_descent_momentum": {
|
|
60
|
+
"aura_path": "python/data-science/optimization_and_distances/gradient_descent_momentum.py",
|
|
61
|
+
"fixture": "gradient_descent_momentum",
|
|
62
|
+
"category": "optimization",
|
|
63
|
+
"description": "Gradient descent with momentum."
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_doc": "Fetch mode's named host sets (design §4a.6 V43-1). Widening a set is a diff here. Decided 2026-11-14 (DECISIONS-7-github G1): github-git for the step-7 cpython fetch; pypi configured, used by no step-7 fetch.",
|
|
3
|
+
"sets": {
|
|
4
|
+
"github-git": ["github.com:443"],
|
|
5
|
+
"pypi": ["pypi.org:443", "files.pythonhosted.org:443"]
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"""ForgeProof caller layer for the debug core. Owns U-code routing.
|
|
2
|
+
|
|
3
|
+
BRIEF-DEBUG-FEATURE-2026-09-05.md §4 and §9 step 2.
|
|
4
|
+
|
|
5
|
+
The debug core (``debug_core.py``) is taxonomy-agnostic by design — it never
|
|
6
|
+
sees a U-code. Routing on U-codes lives HERE, in the forgeproof layer that
|
|
7
|
+
knows about ``LensResult`` and the ``unsupported`` registry. The core imports
|
|
8
|
+
this module NEVER; this module imports the core.
|
|
9
|
+
|
|
10
|
+
Two paths for a FAIL, per §4:
|
|
11
|
+
|
|
12
|
+
FAIL without a U-code -> real defect. Full traceback + intermediate-value
|
|
13
|
+
dump + delta-debug -- populated in step 3+ of the brief. The stub here
|
|
14
|
+
raises NotImplementedError so a caller that hits it before step 3
|
|
15
|
+
lands fails loudly rather than returning an empty payload.
|
|
16
|
+
|
|
17
|
+
FAIL with a U-code -> code-specific evidence path. The diagnosis is
|
|
18
|
+
already scoped by the code; debug only SURFACES what the code carried,
|
|
19
|
+
it does not re-diagnose. §4's table maps each of the five declared
|
|
20
|
+
codes to what it surfaces.
|
|
21
|
+
|
|
22
|
+
The U-code inside a ``LensResult`` today lives in the ``reason`` string,
|
|
23
|
+
formatted by ``Unsupported.summary()`` as ``"[U<n>:<name>] meaning: detail"``.
|
|
24
|
+
We recover the code (and the trailing detail) with a regex whose vocabulary
|
|
25
|
+
is ``declared_codes()`` — an undeclared or missing prefix means "no U-code",
|
|
26
|
+
which sends the FAIL down the real-defect path.
|
|
27
|
+
"""
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
import re
|
|
31
|
+
from typing import Any
|
|
32
|
+
|
|
33
|
+
from forgeproof.debug_core import DebugEvidence, capture_traceback, dump_leaf_locals
|
|
34
|
+
from forgeproof.lenses import LensResult
|
|
35
|
+
from forgeproof.unsupported import declared_codes
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
39
|
+
# Code extraction
|
|
40
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
41
|
+
|
|
42
|
+
_CODE_RE = re.compile(r"^\[(U\d+:[a-z_]+)\]\s*(.*)$", re.DOTALL)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def extract_code(reason: str | None) -> tuple[str | None, str]:
|
|
46
|
+
"""Pull ``(code, remainder)`` out of a LensResult.reason string.
|
|
47
|
+
|
|
48
|
+
Returns ``(None, reason_or_"")`` unchanged when the reason has no
|
|
49
|
+
``[U<n>:name]`` prefix, or when the prefix is malformed or not in
|
|
50
|
+
``declared_codes()``. An unknown code is treated as "no code" rather than
|
|
51
|
+
raising — the router then sends the FAIL to the real-defect path, which
|
|
52
|
+
is the safe default.
|
|
53
|
+
|
|
54
|
+
A non-str reason (``None``, bytes, anything else) is treated as "no code":
|
|
55
|
+
a ``LensResult`` with ``reason=None`` is not forbidden by the dataclass,
|
|
56
|
+
and crashing here would take down the router instead of routing the FAIL
|
|
57
|
+
to the real-defect path. Fixed 2026-09-05 per 6E review Finding 1.
|
|
58
|
+
"""
|
|
59
|
+
if not isinstance(reason, str):
|
|
60
|
+
return None, "" if reason is None else str(reason)
|
|
61
|
+
m = _CODE_RE.match(reason)
|
|
62
|
+
if not m:
|
|
63
|
+
return None, reason
|
|
64
|
+
code = m.group(1)
|
|
65
|
+
if code not in declared_codes():
|
|
66
|
+
return None, reason
|
|
67
|
+
return code, m.group(2)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
71
|
+
# Per-code handlers — each surfaces what §4 says to surface for its code.
|
|
72
|
+
# Handlers take (remainder, lens, extras) and return a partial evidence dict
|
|
73
|
+
# that the router merges into DebugEvidence. Handlers NEVER re-run analysis;
|
|
74
|
+
# they only reshape what the U-code already carried.
|
|
75
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _surface_u1_no_coverage(remainder: str, lens: LensResult, extras: dict) -> dict:
|
|
79
|
+
"""§4: which inputs/patterns are missing from the lens's coverage set.
|
|
80
|
+
|
|
81
|
+
VIEW_COVERAGE is the authoritative map; extras may carry it pre-computed
|
|
82
|
+
(the caller has cheaper access than importing lenses here would be). If
|
|
83
|
+
missing, we surface the reason text alone -- the code already carries
|
|
84
|
+
enough for a human to act.
|
|
85
|
+
"""
|
|
86
|
+
view = extras.get("view_coverage")
|
|
87
|
+
# A wrong-shaped view_coverage (str/list/int — anything but dict) must
|
|
88
|
+
# degrade, not crash. Fixed 2026-09-05 per 6E review Finding 2.
|
|
89
|
+
if not isinstance(view, dict):
|
|
90
|
+
view = {}
|
|
91
|
+
# The value AT the _run_<lens> key must also be defended: a caller who
|
|
92
|
+
# supplies {'_run_metamorphic': 42} (int/None/non-iterable) would crash
|
|
93
|
+
# sorted() with TypeError. Container-guard alone is not enough. Fixed
|
|
94
|
+
# 2026-09-07 per 6E review round-2 Finding 1.
|
|
95
|
+
raw = view.get(f"_run_{lens.name.replace('-', '_')}", [])
|
|
96
|
+
try:
|
|
97
|
+
declared = sorted(raw)
|
|
98
|
+
except TypeError:
|
|
99
|
+
declared = []
|
|
100
|
+
return {
|
|
101
|
+
"missing_from": lens.name,
|
|
102
|
+
"declared_inputs": declared,
|
|
103
|
+
"reason_detail": remainder,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _surface_u2_contract_unratified(remainder: str, lens: LensResult, extras: dict) -> dict:
|
|
108
|
+
"""§4: which contract file, which pattern, ratified: false state.
|
|
109
|
+
|
|
110
|
+
The contract path is not in the LensResult; extras may supply it. If
|
|
111
|
+
absent we surface the code's detail alone.
|
|
112
|
+
"""
|
|
113
|
+
return {
|
|
114
|
+
"contract_path": extras.get("contract_path"),
|
|
115
|
+
"pattern": extras.get("pattern"),
|
|
116
|
+
"ratified": False,
|
|
117
|
+
"reason_detail": remainder,
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _surface_u3_input_malformed(remainder: str, lens: LensResult, extras: dict) -> dict:
|
|
122
|
+
"""§4: which input is absent/malformed. Cause CERTAIN — the disposition
|
|
123
|
+
is FIX or QUARANTINE (per unsupported.py); debug only says WHAT."""
|
|
124
|
+
return {
|
|
125
|
+
"malformed_input": extras.get("input_name"),
|
|
126
|
+
"reason_detail": remainder,
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _surface_u4_capture_failed(remainder: str, lens: LensResult, extras: dict) -> dict:
|
|
131
|
+
"""§4: subprocess exit + stderr tail. The reason already carries the
|
|
132
|
+
stderr tail (lenses.py:364 slices the last 200 chars); we pass it
|
|
133
|
+
through untouched."""
|
|
134
|
+
return {
|
|
135
|
+
"subprocess_stderr_tail": remainder,
|
|
136
|
+
"exit_hint": extras.get("subprocess_exit"),
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _surface_u4_coverage_gap(remainder: str, lens: LensResult, extras: dict) -> dict:
|
|
141
|
+
"""§4: params_aborted / unexercisable list. The guard-lens carries this
|
|
142
|
+
inside the verdict string it hands back; extras may split it out."""
|
|
143
|
+
return {
|
|
144
|
+
"params_aborted": extras.get("params_aborted") or [],
|
|
145
|
+
"unexercisable": extras.get("unexercisable") or [],
|
|
146
|
+
"reason_detail": remainder,
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
_HANDLERS = {
|
|
151
|
+
"U1:no_coverage": _surface_u1_no_coverage,
|
|
152
|
+
"U2:contract_unratified": _surface_u2_contract_unratified,
|
|
153
|
+
"U3:input_malformed": _surface_u3_input_malformed,
|
|
154
|
+
"U4:capture_failed": _surface_u4_capture_failed,
|
|
155
|
+
"U4:coverage_gap": _surface_u4_coverage_gap,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
160
|
+
# Router
|
|
161
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def route(
|
|
165
|
+
lens: LensResult,
|
|
166
|
+
*,
|
|
167
|
+
source_text: str,
|
|
168
|
+
source_origin: str,
|
|
169
|
+
failing_input: Any,
|
|
170
|
+
extras: dict[str, Any] | None = None,
|
|
171
|
+
exception: BaseException | None = None,
|
|
172
|
+
) -> DebugEvidence:
|
|
173
|
+
"""Build a DebugEvidence for one lens's FAIL / UNSUPPORTED verdict.
|
|
174
|
+
|
|
175
|
+
Callers pre-capture ``source_text`` via ``debug_core.capture_source``
|
|
176
|
+
BEFORE any ``finally: unlink()`` in the isolation code — see the
|
|
177
|
+
top-of-file trap in debug_core's module docstring.
|
|
178
|
+
|
|
179
|
+
``extras`` is an opaque dict for per-code side channels the LensResult
|
|
180
|
+
does not carry (contract path, params_aborted list, VIEW_COVERAGE map).
|
|
181
|
+
A missing key is fine; every handler treats absence as "not available"
|
|
182
|
+
and surfaces the code's own detail instead of failing.
|
|
183
|
+
"""
|
|
184
|
+
extras = extras or {}
|
|
185
|
+
code, remainder = extract_code(lens.reason)
|
|
186
|
+
|
|
187
|
+
if code is None:
|
|
188
|
+
return _route_no_code(lens, source_text, source_origin, failing_input, extras, exception)
|
|
189
|
+
|
|
190
|
+
handler = _HANDLERS[code] # KeyError impossible: extract_code filters to declared
|
|
191
|
+
payload = handler(remainder, lens, extras)
|
|
192
|
+
|
|
193
|
+
return DebugEvidence(
|
|
194
|
+
source_text=source_text,
|
|
195
|
+
source_origin=source_origin,
|
|
196
|
+
failing_input=failing_input,
|
|
197
|
+
caller_label=code,
|
|
198
|
+
caller_metadata={
|
|
199
|
+
"lens_name": lens.name,
|
|
200
|
+
"lens_status": lens.status,
|
|
201
|
+
"surfaced": payload,
|
|
202
|
+
},
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _route_no_code(
|
|
207
|
+
lens: LensResult,
|
|
208
|
+
source_text: str,
|
|
209
|
+
source_origin: str,
|
|
210
|
+
failing_input: Any,
|
|
211
|
+
extras: dict[str, Any],
|
|
212
|
+
exception: BaseException | None,
|
|
213
|
+
) -> DebugEvidence:
|
|
214
|
+
"""Real-defect path: this is what fires when a lens says FAIL and the
|
|
215
|
+
reason string carries no U-code. Diagnosis is genuinely open -- the
|
|
216
|
+
code under test is the suspect. We surface a traceback (if an exception
|
|
217
|
+
is available) and the leaf-frame locals at the moment the exception
|
|
218
|
+
surfaced.
|
|
219
|
+
|
|
220
|
+
``exception=None`` is legal: some lenses (metamorphic RELATION-FAIL,
|
|
221
|
+
invariant bounds violation, twin metric disagreement) produce a FAIL
|
|
222
|
+
verdict WITHOUT raising anything -- their contract IS the assertion.
|
|
223
|
+
In that case the returned evidence has ``traceback_text=None`` and
|
|
224
|
+
``intermediate_values`` is only populated if the caller placed a
|
|
225
|
+
pre-computed frame dump in ``extras['leaf_locals']``.
|
|
226
|
+
|
|
227
|
+
Leaf-frame locals only, not a full sys.settrace tracer. A tracer is
|
|
228
|
+
subtle to get right and its failure mode is a crash at the moment the
|
|
229
|
+
user needs debug info most -- see the commit body of step 3 for why
|
|
230
|
+
this scope is intentional.
|
|
231
|
+
"""
|
|
232
|
+
tb_text: str | None = None
|
|
233
|
+
leaf: dict[str, str] | None = None
|
|
234
|
+
|
|
235
|
+
if exception is not None:
|
|
236
|
+
tb_text = capture_traceback(exception)
|
|
237
|
+
# source_only is the path the caller wrote to disk; leaf locals from
|
|
238
|
+
# inside stdlib code would be noise, not evidence.
|
|
239
|
+
filter_path = source_origin if source_origin and source_origin != "<inline>" else None
|
|
240
|
+
leaf = dump_leaf_locals(exception.__traceback__, source_only=filter_path)
|
|
241
|
+
|
|
242
|
+
if leaf is None:
|
|
243
|
+
leaf = extras.get("leaf_locals")
|
|
244
|
+
|
|
245
|
+
# SHRUNK_INPUT (step 6, ddmin-at-lens): the caller may have run ddmin
|
|
246
|
+
# against the failing input and passed the result under extras. Surface
|
|
247
|
+
# it on the DebugEvidence so a formatter can print "minimal reproducer:
|
|
248
|
+
# N lines" alongside the traceback.
|
|
249
|
+
shrunk = extras.get("shrunk_input")
|
|
250
|
+
|
|
251
|
+
# COMPILER_OUTPUT (4Q step-6 review Finding 1, 2026-09-07): the twin
|
|
252
|
+
# lens on C++ compile failure needs its compiler output on the dedicated
|
|
253
|
+
# DebugEvidence.compiler_output field (brief §4.3), not stuffed into
|
|
254
|
+
# intermediate_values. Any caller may pass extras['compiler_output'].
|
|
255
|
+
compiler_out = extras.get("compiler_output")
|
|
256
|
+
|
|
257
|
+
return DebugEvidence(
|
|
258
|
+
source_text=source_text,
|
|
259
|
+
source_origin=source_origin,
|
|
260
|
+
failing_input=failing_input,
|
|
261
|
+
traceback_text=tb_text,
|
|
262
|
+
intermediate_values=leaf,
|
|
263
|
+
compiler_output=compiler_out,
|
|
264
|
+
shrunk_input=shrunk,
|
|
265
|
+
caller_label=None, # explicit: no U-code -> real defect
|
|
266
|
+
caller_metadata={
|
|
267
|
+
"lens_name": lens.name,
|
|
268
|
+
"lens_status": lens.status,
|
|
269
|
+
"path": "real_defect",
|
|
270
|
+
},
|
|
271
|
+
)
|