machinechecked 0.1.9__tar.gz → 0.1.11__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.
- {machinechecked-0.1.9 → machinechecked-0.1.11}/PKG-INFO +1 -1
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/machinechecked.egg-info/PKG-INFO +1 -1
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/machinechecked.egg-info/SOURCES.txt +2 -2
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/assess.py +29 -2
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/cli.py +10 -2
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/config.py +4 -1
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/data/ProofLensProbe.lean +25 -7
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/manifest.py +8 -2
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/paper.py +56 -10
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/pipeline.py +8 -1
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/server.py +11 -6
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/symbols.py +64 -10
- machinechecked-0.1.9/engine/python/prooflens/web/assets/index-CF9Ifrju.css → machinechecked-0.1.11/engine/python/prooflens/web/assets/index-B7NQsymB.css +1 -1
- machinechecked-0.1.11/engine/python/prooflens/web/assets/index-BtJVnEBn.js +286 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/index.html +2 -2
- {machinechecked-0.1.9 → machinechecked-0.1.11}/pyproject.toml +1 -1
- machinechecked-0.1.9/engine/python/prooflens/web/assets/index-CsVq8qV_.js +0 -286
- {machinechecked-0.1.9 → machinechecked-0.1.11}/LICENSE +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/README.md +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/machinechecked.egg-info/dependency_links.txt +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/machinechecked.egg-info/entry_points.txt +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/machinechecked.egg-info/requires.txt +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/machinechecked.egg-info/top_level.txt +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/__init__.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/__main__.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/audit.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/bundle.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/cache.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/data/prooflens.sty +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/data/schema/evidence.schema.json +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/data/schema/inventory.schema.json +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/data/schema/manifest-claim.schema.json +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/data/schema/manifest-index.schema.json +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/deps.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/evidence.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/export.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/formalization.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/pdfclaims.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/probe.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/promote.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/replay.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/review_cli.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/review_queue.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/reviews.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/schemas.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/simple.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/sources.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/tex.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/util.py +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/web/theme.css +0 -0
- {machinechecked-0.1.9 → machinechecked-0.1.11}/setup.cfg +0 -0
{machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/machinechecked.egg-info/SOURCES.txt
RENAMED
|
@@ -63,6 +63,6 @@ engine/python/prooflens/web/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2
|
|
|
63
63
|
engine/python/prooflens/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2
|
|
64
64
|
engine/python/prooflens/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2
|
|
65
65
|
engine/python/prooflens/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2
|
|
66
|
-
engine/python/prooflens/web/assets/index-
|
|
67
|
-
engine/python/prooflens/web/assets/index-
|
|
66
|
+
engine/python/prooflens/web/assets/index-B7NQsymB.css
|
|
67
|
+
engine/python/prooflens/web/assets/index-BtJVnEBn.js
|
|
68
68
|
engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs
|
|
@@ -442,7 +442,10 @@ class Assessor:
|
|
|
442
442
|
consistency = [f["message"] for f in mine]
|
|
443
443
|
reasons = []
|
|
444
444
|
t = (self.tex or {}).get(pid, {})
|
|
445
|
-
|
|
445
|
+
source = t.get("mode") or "none"
|
|
446
|
+
if source == "pdf":
|
|
447
|
+
reasons += self._pdf_source(pid, t)
|
|
448
|
+
elif source != "latex":
|
|
446
449
|
reasons.append("sources: manuscript source not compiled, source hashes unchecked")
|
|
447
450
|
if self.lean is None:
|
|
448
451
|
reasons.append("lean: the Lean project was not checked")
|
|
@@ -472,11 +475,35 @@ class Assessor:
|
|
|
472
475
|
if not comparator:
|
|
473
476
|
reasons.append("comparator: no successful kernel replay covering every proof "
|
|
474
477
|
"of the paper")
|
|
475
|
-
out[pid] = {"
|
|
478
|
+
out[pid] = {"source": source,
|
|
479
|
+
**({"source_note": "the source is a PDF: its hash is pinned and checked, "
|
|
480
|
+
"and claim positions are approximate"} if source == "pdf" else {}),
|
|
481
|
+
"consistency": {"pass": not consistency, "failures": consistency},
|
|
476
482
|
"release": {"pass": not reasons, "reasons": reasons},
|
|
477
483
|
"comparator": comparator}
|
|
478
484
|
return out
|
|
479
485
|
|
|
486
|
+
def _pdf_source(self, pid: str, t: dict) -> list[str]:
|
|
487
|
+
"""Why a paper whose source is a PDF does not meet the gate's source condition: the PDF
|
|
488
|
+
is pinned by the configuration (`pdf_sha256`) and matches it, and every claim in scope
|
|
489
|
+
is found in it (by its heading, or placed by hand in `anchors.json`)."""
|
|
490
|
+
out = []
|
|
491
|
+
pinned, actual = t.get("pdf_pinned"), t.get("pdf_sha256")
|
|
492
|
+
if not pinned:
|
|
493
|
+
out.append("sources: the paper is a PDF and its hash is not pinned (pdf_sha256 in "
|
|
494
|
+
"machinechecked.toml), so it is not checked")
|
|
495
|
+
elif pinned != actual:
|
|
496
|
+
out.append(f"sources: the PDF differs from the one pinned (sha256 {str(actual)[:12]}, "
|
|
497
|
+
f"pinned {pinned[:12]})")
|
|
498
|
+
manual = t.get("manual_anchors") or {}
|
|
499
|
+
for c in self.inv["claims"]:
|
|
500
|
+
if c["paper"] != pid or c["scope"] in OUT_OF_SCOPE:
|
|
501
|
+
continue
|
|
502
|
+
if c["id"] not in manual and match_anchor(c, t.get("anchors", [])) is None:
|
|
503
|
+
out.append(f"sources: {c['id']} ({c.get('number') or 'unnumbered'}) is not found "
|
|
504
|
+
"in the PDF; place it by hand in anchors.json")
|
|
505
|
+
return out
|
|
506
|
+
|
|
480
507
|
# -- inventory against the compiled paper ---------------------------------------------
|
|
481
508
|
|
|
482
509
|
def inventory_checks(self):
|
|
@@ -228,7 +228,12 @@ def cmd_view(a):
|
|
|
228
228
|
res = build(cfg, web_dist=_web_dist(a.web), reuse_lean=True)
|
|
229
229
|
except RuntimeError:
|
|
230
230
|
res = build(cfg, web_dist=_web_dist(a.web))
|
|
231
|
-
|
|
231
|
+
|
|
232
|
+
def on_symbol(req):
|
|
233
|
+
from .symbols import from_reader
|
|
234
|
+
from_reader(cfg, req, _web_dist(a.web))
|
|
235
|
+
|
|
236
|
+
serve(res["site"], a.port, None, not a.no_browser, on_symbol=on_symbol)
|
|
232
237
|
return
|
|
233
238
|
from .server import serve
|
|
234
239
|
from .simple import save_link
|
|
@@ -531,7 +536,8 @@ def cmd_symbol(a):
|
|
|
531
536
|
cfg = cfgmod.load(_config_arg(a))
|
|
532
537
|
try:
|
|
533
538
|
if a.action == "add":
|
|
534
|
-
ln = sy.add(cfg, a.claim, a.tex, a.decl, a.reviewer, var=a.var, type_of=a.type_of
|
|
539
|
+
ln = sy.add(cfg, a.claim, a.tex, a.decl, a.reviewer, var=a.var, type_of=a.type_of,
|
|
540
|
+
term=a.term)
|
|
535
541
|
print(f"linked {a.tex} in {a.claim} to {ln['lean']} (by {ln['by']}); "
|
|
536
542
|
"rebuild the site to show it")
|
|
537
543
|
elif a.action == "remove":
|
|
@@ -802,6 +808,8 @@ def main(argv=None):
|
|
|
802
808
|
p_.add_argument("decl", help="the claim's Lean statement")
|
|
803
809
|
p_.add_argument("--var", help="the variable it is (a binder's name or index)")
|
|
804
810
|
p_.add_argument("--type-of", dest="type_of", help="the binder whose type it is")
|
|
811
|
+
p_.add_argument("--term", help="the sub-term it is, as WHERE#K: b:<binder>, c (the "
|
|
812
|
+
"conclusion) or l:<part>, and the sub-term's number")
|
|
805
813
|
p_.add_argument("--as", dest="reviewer",
|
|
806
814
|
default=os.environ.get("MACHINECHECKED_REVIEWER"),
|
|
807
815
|
help="human:NAME or llm:MODEL (default: $MACHINECHECKED_REVIEWER)")
|
|
@@ -38,6 +38,9 @@ class Paper:
|
|
|
38
38
|
# a DOI or a URL), and how the revision differs from it. Descriptive only: no status uses it.
|
|
39
39
|
published: str | None = None
|
|
40
40
|
published_note: str | None = None
|
|
41
|
+
# A paper whose source is a PDF: the PDF's SHA-256, pinned by the configuration. The release
|
|
42
|
+
# gate accepts a PDF as source evidence only when it is pinned and matches (EVIDENCE_POLICY).
|
|
43
|
+
pdf_sha256: str | None = None
|
|
41
44
|
|
|
42
45
|
|
|
43
46
|
@dataclass
|
|
@@ -117,7 +120,7 @@ def load(path: str | Path) -> Config:
|
|
|
117
120
|
raise ConfigError(f"paper {p.get('id')}: source needs one of path, git, arxiv")
|
|
118
121
|
papers.append(Paper(
|
|
119
122
|
id=_req(p, "id", "paper"), title=p.get("title", p["id"]), source=src,
|
|
120
|
-
root=p.get("root"), pdf=p.get("pdf"), commit=src.get("rev"), envs=p.get("envs"),
|
|
123
|
+
root=p.get("root"), pdf=p.get("pdf"), pdf_sha256=p.get("pdf_sha256"), commit=src.get("rev"), envs=p.get("envs"),
|
|
121
124
|
publish=Publish(**p.get("publish", {})), published=p.get("published"),
|
|
122
125
|
published_note=p.get("note")))
|
|
123
126
|
return Config(
|
{machinechecked-0.1.9 → machinechecked-0.1.11}/engine/python/prooflens/data/ProofLensProbe.lean
RENAMED
|
@@ -167,15 +167,18 @@ def constPrint (ci : ConstantInfo) : MetaM (String × String × Array Name) := d
|
|
|
167
167
|
|
|
168
168
|
/-- Flatten tagged code into segments; a segment carries the constant it names (`ref`), or the
|
|
169
169
|
index of the statement's binder it refers to (`var`, a position in `vars`), when the innermost
|
|
170
|
-
subexpression around it is one.
|
|
170
|
+
subexpression around it is one. Each tagged subexpression is also recorded as the range of
|
|
171
|
+
segments it covers (`terms`, in printing order, an outer one before those inside it), so that the
|
|
172
|
+
reader can select a whole sub-term. -/
|
|
171
173
|
partial def segments (vars : Array FVarId) (t : Widget.CodeWithInfos) (ref : Option (String × Json))
|
|
172
|
-
(acc : Array Json) : Array Json :=
|
|
174
|
+
(acc : Array Json) (terms : Array (Nat × Nat)) : Array Json × Array (Nat × Nat) :=
|
|
173
175
|
match t with
|
|
174
176
|
| Widget.TaggedText.text s =>
|
|
175
177
|
match ref with
|
|
176
|
-
| some (k, v) => acc.push (Json.mkObj [("t", s), (k, v)])
|
|
177
|
-
| none => acc.push (Json.mkObj [("t", s)])
|
|
178
|
-
| Widget.TaggedText.append xs =>
|
|
178
|
+
| some (k, v) => (acc.push (Json.mkObj [("t", s), (k, v)]), terms)
|
|
179
|
+
| none => (acc.push (Json.mkObj [("t", s)]), terms)
|
|
180
|
+
| Widget.TaggedText.append xs =>
|
|
181
|
+
xs.foldl (fun (a, ts) x => segments vars x ref a ts) (acc, terms)
|
|
179
182
|
| Widget.TaggedText.tag info sub =>
|
|
180
183
|
let r := match info.info.val.info with
|
|
181
184
|
| .ofTermInfo ti => match ti.expr with
|
|
@@ -183,7 +186,21 @@ partial def segments (vars : Array FVarId) (t : Widget.CodeWithInfos) (ref : Opt
|
|
|
183
186
|
| .fvar id => (vars.findIdx? (· == id)).map fun i => ("var", toJson i)
|
|
184
187
|
| _ => none
|
|
185
188
|
| _ => none
|
|
186
|
-
|
|
189
|
+
let start := acc.size
|
|
190
|
+
let slot := terms.size
|
|
191
|
+
let (acc', terms') := segments vars sub r acc (terms.push (start, start))
|
|
192
|
+
(acc', terms'.set! slot (start, acc'.size))
|
|
193
|
+
|
|
194
|
+
/-- The sub-terms worth selecting: those covering two segments or more, each range once (the
|
|
195
|
+
outermost tag of a range keeps it), and none for a very large term. -/
|
|
196
|
+
def termsJson (terms : Array (Nat × Nat)) : Json := Id.run do
|
|
197
|
+
let mut out : Array Json := #[]
|
|
198
|
+
let mut seen : Array (Nat × Nat) := #[]
|
|
199
|
+
for (a, b) in terms do
|
|
200
|
+
if b - a ≥ 2 && !seen.contains (a, b) then
|
|
201
|
+
seen := seen.push (a, b)
|
|
202
|
+
out := out.push (Json.mkObj [("from", toJson a), ("to", toJson b)])
|
|
203
|
+
return Json.arr (if out.size > 3000 then #[] else out)
|
|
187
204
|
|
|
188
205
|
/-- The fields of a pretty-printed expression with navigable constants and binders; plain text
|
|
189
206
|
if tagging fails, and a marker if printing fails, so that one large term cannot stop the probe. -/
|
|
@@ -193,7 +210,8 @@ def ppFields (e : Expr) (vars : Array FVarId := #[]) : MetaM (List (String × Js
|
|
|
193
210
|
-- term applies is a constant the reader can name; the text is the same.
|
|
194
211
|
let code ← withOptions (fun o => o.setBool `pp.tagAppFns true) (Widget.ppExprTagged e)
|
|
195
212
|
let text := toString (← ppExpr e)
|
|
196
|
-
|
|
213
|
+
let (segs, terms) := segments vars code none #[] #[]
|
|
214
|
+
return [("text", Json.str text), ("segments", Json.arr segs), ("terms", termsJson terms)]
|
|
197
215
|
catch _ =>
|
|
198
216
|
try
|
|
199
217
|
return [("text", Json.str (toString (← ppExpr e)))]
|
|
@@ -175,9 +175,15 @@ def build(evidence: dict, release: str, display: dict | None = None
|
|
|
175
175
|
for c in inv:
|
|
176
176
|
a = assessed[c["id"]]
|
|
177
177
|
t = tex.get(c["paper"], {})
|
|
178
|
-
anchor = match_anchor(c, t.get("anchors", [])) if t.get("mode")
|
|
178
|
+
anchor = match_anchor(c, t.get("anchors", [])) if t.get("mode") in ("latex", "pdf") \
|
|
179
|
+
else None
|
|
179
180
|
src_ok = None
|
|
180
|
-
if anchor:
|
|
181
|
+
if anchor and t.get("mode") == "pdf":
|
|
182
|
+
# Found by its heading in the PDF: where it ends is estimated.
|
|
183
|
+
anchor = {**anchor, "kind": "approximate"}
|
|
184
|
+
elif anchor:
|
|
185
|
+
# (The inventory's source hash is of the LaTeX statement; a PDF's extracted text
|
|
186
|
+
# cannot be compared with it.)
|
|
181
187
|
anchor = {**anchor, "kind": "exact"}
|
|
182
188
|
if c.get("source_sha256") and anchor.get("source_sha256"):
|
|
183
189
|
src_ok = anchor["source_sha256"] == c["source_sha256"]
|
|
@@ -4,8 +4,11 @@ states it formalises the paper, the declarations its `formalization.yaml` maps t
|
|
|
4
4
|
It is written in the reader's standard data format (`data/index.json`, `data/claims/`), so a
|
|
5
5
|
paper page is read by the same code as a view or an audit. Nothing here runs Lean, so a mapped
|
|
6
6
|
statement reads "linked: Lean not checked here (no audit published)": the link says which
|
|
7
|
-
declaration the project names, not what Lean establishes.
|
|
8
|
-
|
|
7
|
+
declaration the project names, not what Lean establishes. When the project has a published
|
|
8
|
+
audit that lists a claim of the same printed number, the statement shows that claim's status as
|
|
9
|
+
the audit records it, credited to the audit's author and linked to it (`apply_audits`): the
|
|
10
|
+
audit's words, not the site's. Each project's links and statuses are kept apart (`by_project`);
|
|
11
|
+
the reader shows one project at a time and never combines them.
|
|
9
12
|
|
|
10
13
|
No statement's text is written: only its number, heading title and place on the page.
|
|
11
14
|
"""
|
|
@@ -21,6 +24,7 @@ from .util import content_id
|
|
|
21
24
|
|
|
22
25
|
SCHEMA = "prooflens/manifest@0"
|
|
23
26
|
NOT_CHECKED = "linked: Lean not checked here (no audit published)"
|
|
27
|
+
NOT_IN_AUDIT = "linked: Lean not checked here (the published audit does not list it)"
|
|
24
28
|
NOT_LINKED = "not linked"
|
|
25
29
|
NAME = re.compile(r"[\w.'«»]+")
|
|
26
30
|
|
|
@@ -47,8 +51,44 @@ def paper_claims(anchors: list[dict], title: str,
|
|
|
47
51
|
return out
|
|
48
52
|
|
|
49
53
|
|
|
50
|
-
def
|
|
51
|
-
|
|
54
|
+
def apply_audits(claims: list[dict], audits: dict[str, dict]) -> list[dict]:
|
|
55
|
+
"""Each statement (from `paper_claims`) with, for every project whose published audit lists
|
|
56
|
+
exactly one claim of the same printed number, that claim as the audit records it (`audit`:
|
|
57
|
+
status, class, claim id, link, author). When the project's formalization.yaml declares no
|
|
58
|
+
link for the statement, the audit's Lean names are its links. `audits` maps a repository to
|
|
59
|
+
`{"author", "url", "commit", "claims": [{"id", "number", "status", "class", "lean",
|
|
60
|
+
"link"}]}`, read from the audit's own data; the claims are not changed otherwise."""
|
|
61
|
+
for c in claims:
|
|
62
|
+
c["audit"] = {}
|
|
63
|
+
for repo, au in audits.items():
|
|
64
|
+
same = [x for x in au.get("claims", []) if x.get("number") == c["number"]]
|
|
65
|
+
if len(same) != 1:
|
|
66
|
+
continue
|
|
67
|
+
x = same[0]
|
|
68
|
+
c["audit"][repo] = {"status": x["status"], "class": x["class"], "claim": x["id"],
|
|
69
|
+
"link": x.get("link"), "author": au.get("author"),
|
|
70
|
+
"audit": au.get("url")}
|
|
71
|
+
if not any(l["repository"] == repo for l in c["links"]):
|
|
72
|
+
c["links"] = c["links"] + [
|
|
73
|
+
{"name": n, "repository": repo, "commit": au.get("commit"),
|
|
74
|
+
"source": "audit"} for n in x.get("lean", []) if NAME.fullmatch(n)]
|
|
75
|
+
return claims
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _state(links: list[dict], audit: dict | None = None,
|
|
79
|
+
audited: bool = False) -> tuple[str, str]:
|
|
80
|
+
"""A statement's status for one project: the audit's own, when its published audit lists
|
|
81
|
+
the statement; otherwise what the page can say without Lean."""
|
|
82
|
+
if audit:
|
|
83
|
+
return audit["status"], audit["class"]
|
|
84
|
+
if not links:
|
|
85
|
+
return NOT_LINKED, "unspecified"
|
|
86
|
+
return (NOT_IN_AUDIT if audited else NOT_CHECKED), "declared"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _link_state(link: dict, audit: dict | None, audited: bool) -> dict:
|
|
90
|
+
status, cls = _state([link], audit, audited)
|
|
91
|
+
return {"status": status, "class": cls}
|
|
52
92
|
|
|
53
93
|
|
|
54
94
|
def write_paper_site(site: Path, paper: dict, claims: list[dict],
|
|
@@ -60,17 +100,22 @@ def write_paper_site(site: Path, paper: dict, claims: list[dict],
|
|
|
60
100
|
`paper_claims`. Replaces whatever is at `site`."""
|
|
61
101
|
from .pipeline import write_preview
|
|
62
102
|
projects = [f["repository"] for f in paper.get("formalisations", [])]
|
|
103
|
+
audited = {f["repository"] for f in paper.get("formalisations", []) if f.get("audits")}
|
|
63
104
|
index_claims, chunks = [], {}
|
|
64
105
|
for c in claims:
|
|
65
106
|
cid = f"P:{c['key']}"
|
|
66
107
|
fname = mf.claim_file(cid)
|
|
67
108
|
anchor = {**c["anchor"], "kind": "approximate"} if c.get("anchor") else None
|
|
68
109
|
by_project = {}
|
|
110
|
+
audits = c.get("audit") or {}
|
|
69
111
|
for r in projects:
|
|
70
|
-
status, cls = _state([l for l in c["links"] if l["repository"] == r])
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
112
|
+
status, cls = _state([l for l in c["links"] if l["repository"] == r], audits.get(r),
|
|
113
|
+
r in audited)
|
|
114
|
+
by_project[r] = {"status": status, "class": cls,
|
|
115
|
+
**({"audit": audits[r]} if r in audits else {})}
|
|
116
|
+
first = projects[0] if projects else None
|
|
117
|
+
status, cls = _state([l for l in c["links"] if not projects or l["repository"] == first],
|
|
118
|
+
audits.get(first), first in audited)
|
|
74
119
|
common = {"id": cid, "paper": "P", "number": c["number"], "title": c.get("title"),
|
|
75
120
|
"heading": c.get("title") or None, "kind": c["kind"], "scope": "formal",
|
|
76
121
|
"status": status, "class": cls, "by_project": by_project}
|
|
@@ -81,8 +126,9 @@ def write_paper_site(site: Path, paper: dict, claims: list[dict],
|
|
|
81
126
|
**common, "schema": SCHEMA, "mode": "simple", "release": "paper", "key": c["key"],
|
|
82
127
|
"scope_note": "", "scope_reviewed": True, "anchor": anchor,
|
|
83
128
|
"source_matches": None, "statement_tex": None, "blockers": [],
|
|
84
|
-
"links": [{**l,
|
|
85
|
-
|
|
129
|
+
"links": [{**l, **_link_state(l, audits.get(l["repository"]),
|
|
130
|
+
l["repository"] in audited),
|
|
131
|
+
"why": None, "statement": None, "path": None} for l in c["links"]],
|
|
86
132
|
"suggestions": [], "clauses": [], "decls": {}, "findings": []}
|
|
87
133
|
summary = {}
|
|
88
134
|
for c in index_claims:
|
|
@@ -112,7 +112,14 @@ def build(cfg: Config, release: str | None = None, skip_lean: bool = False,
|
|
|
112
112
|
prov["pdf_origin"] = "compiled"
|
|
113
113
|
pdfs[paper.id] = t["pdf"]
|
|
114
114
|
elif snap.pdf:
|
|
115
|
-
|
|
115
|
+
# The source is a PDF: its numbered statements are found by their bold headings
|
|
116
|
+
# (positions approximate). The PDF counts as source evidence for the release gate
|
|
117
|
+
# only when the configuration pins its hash and it matches.
|
|
118
|
+
from .pdfclaims import claims_from_pdf
|
|
119
|
+
anchors, size = claims_from_pdf(snap.dir / snap.pdf)
|
|
120
|
+
tex[paper.id] = {"mode": "pdf", "anchors": anchors, "page_size": size, "inputs": [],
|
|
121
|
+
"pdf_sha256": prov["committed_pdf_sha256"],
|
|
122
|
+
"pdf_pinned": paper.pdf_sha256}
|
|
116
123
|
prov["mode"] = "pdf"
|
|
117
124
|
prov["pdf_sha256"] = prov["committed_pdf_sha256"]
|
|
118
125
|
prov["pdf_origin"] = "committed"
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
It listens on 127.0.0.1 only. `GET /api/status` tells the reader it may edit; `POST /api/link`
|
|
4
4
|
with `{"key", "lean": [names] | null, "reject": [names]}` records a link (or removes it, or
|
|
5
|
-
rejects suggestions) in `prooflens.links.json` and rebuilds the view.
|
|
5
|
+
rejects suggestions) in `prooflens.links.json` and rebuilds the view. In a full assessment,
|
|
6
|
+
`POST /api/symbol` with `{"action": "add" | "remove", "claim", "tex", "decl", "var" | "type_of",
|
|
7
|
+
"by"}` records or removes a symbol link (docs/SYMBOL_LINKS.md) and rewrites the site.
|
|
6
8
|
"""
|
|
7
9
|
|
|
8
10
|
from __future__ import annotations
|
|
@@ -14,8 +16,10 @@ import threading
|
|
|
14
16
|
from pathlib import Path
|
|
15
17
|
|
|
16
18
|
|
|
17
|
-
def serve(site: Path, port: int, on_link=None, open_browser: bool = True):
|
|
19
|
+
def serve(site: Path, port: int, on_link=None, open_browser: bool = True, on_symbol=None):
|
|
18
20
|
lock = threading.Lock()
|
|
21
|
+
editable = on_link is not None or on_symbol is not None
|
|
22
|
+
routes = {"/api/link": on_link, "/api/symbol": on_symbol}
|
|
19
23
|
|
|
20
24
|
class Handler(http.server.SimpleHTTPRequestHandler):
|
|
21
25
|
def log_message(self, *a):
|
|
@@ -31,10 +35,10 @@ def serve(site: Path, port: int, on_link=None, open_browser: bool = True):
|
|
|
31
35
|
|
|
32
36
|
def do_GET(self):
|
|
33
37
|
if self.path == "/api/status":
|
|
34
|
-
return self._json(200, {"editable":
|
|
38
|
+
return self._json(200, {"editable": editable})
|
|
35
39
|
# The data index says the page may edit (only this local server says so; a static
|
|
36
40
|
# copy of the site never asks a server anything).
|
|
37
|
-
if self.path.split("?")[0] == "/data/index.json" and
|
|
41
|
+
if self.path.split("?")[0] == "/data/index.json" and editable:
|
|
38
42
|
try:
|
|
39
43
|
data = json.loads((site / "data" / "index.json").read_text(encoding="utf-8"))
|
|
40
44
|
except (OSError, ValueError):
|
|
@@ -43,13 +47,14 @@ def serve(site: Path, port: int, on_link=None, open_browser: bool = True):
|
|
|
43
47
|
return super().do_GET()
|
|
44
48
|
|
|
45
49
|
def do_POST(self):
|
|
46
|
-
|
|
50
|
+
handle = routes.get(self.path)
|
|
51
|
+
if handle is None:
|
|
47
52
|
return self._json(404, {"error": "not found"})
|
|
48
53
|
try:
|
|
49
54
|
n = int(self.headers.get("Content-Length", "0"))
|
|
50
55
|
req = json.loads(self.rfile.read(n) or b"{}")
|
|
51
56
|
with lock:
|
|
52
|
-
|
|
57
|
+
handle(req)
|
|
53
58
|
return self._json(200, {"ok": True})
|
|
54
59
|
except Exception as e: # the reader shows the message
|
|
55
60
|
return self._json(400, {"error": str(e)})
|
|
@@ -36,16 +36,41 @@ def _in_math(tex: str, symbol: str) -> bool:
|
|
|
36
36
|
return any(re.search(pat, s) for s in spans)
|
|
37
37
|
|
|
38
38
|
|
|
39
|
+
def _term_pp(spec: dict, where: str) -> dict | None:
|
|
40
|
+
"""The pretty-printed term a sub-term's place names: `b:<i>` a binder's type, `c` the
|
|
41
|
+
conclusion, `l:<n>` the n-th part of a conclusion split by its logic."""
|
|
42
|
+
concl = spec.get("conclusion") or {}
|
|
43
|
+
if where == "c":
|
|
44
|
+
return concl
|
|
45
|
+
if where.startswith("b:") and where[2:].isdigit():
|
|
46
|
+
bs = spec.get("binders", [])
|
|
47
|
+
i = int(where[2:])
|
|
48
|
+
return bs[i].get("type") if i < len(bs) else None
|
|
49
|
+
if where.startswith("l:") and where[2:].isdigit():
|
|
50
|
+
leaves = []
|
|
51
|
+
|
|
52
|
+
def walk(n):
|
|
53
|
+
if "leaf" in n:
|
|
54
|
+
leaves.append(n["leaf"])
|
|
55
|
+
for a in n.get("args", []):
|
|
56
|
+
walk(a)
|
|
57
|
+
if concl.get("logic"):
|
|
58
|
+
walk(concl["logic"])
|
|
59
|
+
n = int(where[2:])
|
|
60
|
+
return leaves[n] if n < len(leaves) else None
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
|
|
39
64
|
def add(cfg: Config, claim: str, symbol: str, decl: str, by: str, var: str | None = None,
|
|
40
|
-
type_of: str | None = None) -> dict:
|
|
65
|
+
type_of: str | None = None, term: str | None = None) -> dict:
|
|
41
66
|
"""Record a link from `symbol` in `claim`'s printed statement to the variable `var` (or the
|
|
42
67
|
type of the binder `type_of`) of the Lean statement `decl`, by `by`."""
|
|
43
68
|
from .pipeline import lean_inputs_digest
|
|
44
69
|
from .promote import latest_record
|
|
45
70
|
if not re.fullmatch(r"(human|llm):\S+", by or ""):
|
|
46
71
|
raise SymbolError("name the link's author as human:NAME or llm:MODEL (--as)")
|
|
47
|
-
if (
|
|
48
|
-
raise SymbolError("give exactly one of --var NAME
|
|
72
|
+
if sum(x is not None for x in (var, type_of, term)) != 1:
|
|
73
|
+
raise SymbolError("give exactly one of --var NAME, --type-of NAME and --term WHERE#K")
|
|
49
74
|
record = latest_record(cfg)
|
|
50
75
|
body = record["body"]
|
|
51
76
|
if body["provenance"].get("lean_inputs_sha256") != lean_inputs_digest(cfg):
|
|
@@ -62,13 +87,21 @@ def add(cfg: Config, claim: str, symbol: str, decl: str, by: str, var: str | Non
|
|
|
62
87
|
raise SymbolError(f"{symbol!r} does not occur in the mathematics of {claim}'s printed "
|
|
63
88
|
"statement")
|
|
64
89
|
spec = (body.get("lean") or {}).get("specs", {}).get(decl) or {}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{"decl": decl, "
|
|
90
|
+
if term is not None:
|
|
91
|
+
where, _, k = term.partition("#")
|
|
92
|
+
pp = _term_pp(spec, where)
|
|
93
|
+
if pp is None or not k.isdigit() or int(k) >= len(pp.get("terms") or []):
|
|
94
|
+
raise SymbolError(f"{decl} has no sub-term {term!r} (WHERE#K: b:<binder>, c or "
|
|
95
|
+
"l:<part>, then the sub-term's number)")
|
|
96
|
+
target = {"decl": decl, "term": int(k), "in": where}
|
|
97
|
+
else:
|
|
98
|
+
names = [b.get("name") for b in spec.get("binders", [])]
|
|
99
|
+
want = var if var is not None else type_of
|
|
100
|
+
idx = int(want) if want.isdigit() else (names.index(want) if want in names else None)
|
|
101
|
+
if idx is None or not 0 <= idx < len(names):
|
|
102
|
+
raise SymbolError(f"{decl} has no binder {want!r} (it has {', '.join(names)})")
|
|
103
|
+
target = {"decl": decl, "var": idx} if var is not None else \
|
|
104
|
+
{"decl": decl, "binder": idx, "path": "type"}
|
|
72
105
|
link = {"claim": claim, "symbol": {"tex": symbol, "occurrence": "all"}, "lean": target,
|
|
73
106
|
"by": by, "pins": {"statement": spec.get("fingerprint"), "source": sha256_text(tex)}}
|
|
74
107
|
data = read_json(cfg.symbols) if cfg.symbols.exists() else {"schema": SCHEMA, "links": []}
|
|
@@ -95,3 +128,24 @@ def listing(cfg: Config) -> str:
|
|
|
95
128
|
return "no symbol links"
|
|
96
129
|
return "\n".join(f"{ln['claim']} {ln['symbol']['tex']} -> {json.dumps(ln['lean'])} "
|
|
97
130
|
f"(by {ln['by']})" for ln in read_json(cfg.symbols).get("links", []))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def from_reader(cfg: Config, req: dict, web_dist=None) -> None:
|
|
134
|
+
"""A symbol link made or removed in the local reader (`POST /api/symbol`), with the checks
|
|
135
|
+
of `symbol add`; the site is then rewritten from the stored evidence (links are display
|
|
136
|
+
only, so nothing is probed or assessed again)."""
|
|
137
|
+
from .pipeline import rebuild_site
|
|
138
|
+
|
|
139
|
+
def text(v):
|
|
140
|
+
return None if v is None else str(v)
|
|
141
|
+
if not isinstance(req.get("claim"), str) or not isinstance(req.get("tex"), str):
|
|
142
|
+
raise SymbolError("a symbol request names a claim and a symbol")
|
|
143
|
+
if req.get("action") == "remove":
|
|
144
|
+
remove(cfg, req["claim"], req["tex"])
|
|
145
|
+
elif req.get("action") == "add":
|
|
146
|
+
add(cfg, req["claim"], req["tex"], str(req.get("decl") or ""), req.get("by"),
|
|
147
|
+
var=text(req.get("var")), type_of=text(req.get("type_of")),
|
|
148
|
+
term=text(req.get("term")))
|
|
149
|
+
else:
|
|
150
|
+
raise SymbolError(f"unknown action {req.get('action')!r}")
|
|
151
|
+
rebuild_site(cfg, web_dist, None)
|