machinechecked 0.1.9__tar.gz → 0.1.10__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.
Files changed (71) hide show
  1. {machinechecked-0.1.9 → machinechecked-0.1.10}/PKG-INFO +1 -1
  2. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/PKG-INFO +1 -1
  3. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/SOURCES.txt +2 -2
  4. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/cli.py +10 -2
  5. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/data/ProofLensProbe.lean +25 -7
  6. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/server.py +11 -6
  7. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/symbols.py +64 -10
  8. machinechecked-0.1.10/engine/python/prooflens/web/assets/index-B97yx2Rs.js +286 -0
  9. machinechecked-0.1.9/engine/python/prooflens/web/assets/index-CF9Ifrju.css → machinechecked-0.1.10/engine/python/prooflens/web/assets/index-Cm5G8Hy5.css +1 -1
  10. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/index.html +2 -2
  11. {machinechecked-0.1.9 → machinechecked-0.1.10}/pyproject.toml +1 -1
  12. machinechecked-0.1.9/engine/python/prooflens/web/assets/index-CsVq8qV_.js +0 -286
  13. {machinechecked-0.1.9 → machinechecked-0.1.10}/LICENSE +0 -0
  14. {machinechecked-0.1.9 → machinechecked-0.1.10}/README.md +0 -0
  15. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/dependency_links.txt +0 -0
  16. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/entry_points.txt +0 -0
  17. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/requires.txt +0 -0
  18. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/top_level.txt +0 -0
  19. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/__init__.py +0 -0
  20. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/__main__.py +0 -0
  21. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/assess.py +0 -0
  22. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/audit.py +0 -0
  23. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/bundle.py +0 -0
  24. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/cache.py +0 -0
  25. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/config.py +0 -0
  26. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/data/prooflens.sty +0 -0
  27. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/data/schema/evidence.schema.json +0 -0
  28. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/data/schema/inventory.schema.json +0 -0
  29. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/data/schema/manifest-claim.schema.json +0 -0
  30. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/data/schema/manifest-index.schema.json +0 -0
  31. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/deps.py +0 -0
  32. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/evidence.py +0 -0
  33. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/export.py +0 -0
  34. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/formalization.py +0 -0
  35. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/manifest.py +0 -0
  36. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/paper.py +0 -0
  37. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/pdfclaims.py +0 -0
  38. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/pipeline.py +0 -0
  39. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/probe.py +0 -0
  40. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/promote.py +0 -0
  41. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/replay.py +0 -0
  42. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/review_cli.py +0 -0
  43. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/review_queue.py +0 -0
  44. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/reviews.py +0 -0
  45. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/schemas.py +0 -0
  46. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/simple.py +0 -0
  47. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/sources.py +0 -0
  48. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/tex.py +0 -0
  49. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/util.py +0 -0
  50. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  51. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  52. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  53. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  54. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  55. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  56. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  57. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  58. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  59. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  60. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  61. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  62. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  63. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  64. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  65. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  66. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  67. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  68. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  69. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs +0 -0
  70. {machinechecked-0.1.9 → machinechecked-0.1.10}/engine/python/prooflens/web/theme.css +0 -0
  71. {machinechecked-0.1.9 → machinechecked-0.1.10}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: machinechecked
3
- Version: 0.1.9
3
+ Version: 0.1.10
4
4
  Summary: Read a mathematical paper beside its Lean formalisation, and see claim by claim what Lean establishes.
5
5
  License: Apache-2.0
6
6
  Project-URL: Homepage, https://machinechecked.org
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: machinechecked
3
- Version: 0.1.9
3
+ Version: 0.1.10
4
4
  Summary: Read a mathematical paper beside its Lean formalisation, and see claim by claim what Lean establishes.
5
5
  License: Apache-2.0
6
6
  Project-URL: Homepage, https://machinechecked.org
@@ -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-CF9Ifrju.css
67
- engine/python/prooflens/web/assets/index-CsVq8qV_.js
66
+ engine/python/prooflens/web/assets/index-B97yx2Rs.js
67
+ engine/python/prooflens/web/assets/index-Cm5G8Hy5.css
68
68
  engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs
@@ -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
- serve(res["site"], a.port, None, not a.no_browser)
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)")
@@ -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 => xs.foldl (fun a x => segments vars x ref a) acc
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
- segments vars sub r acc
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
- return [("text", Json.str text), ("segments", Json.arr (segments vars code none #[]))]
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)))]
@@ -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": on_link is not None})
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 on_link is not None:
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
- if self.path != "/api/link" or on_link is None:
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
- on_link(req)
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 (var is None) == (type_of is None):
48
- raise SymbolError("give exactly one of --var NAME and --type-of 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
- names = [b.get("name") for b in spec.get("binders", [])]
66
- want = var if var is not None else type_of
67
- idx = int(want) if want.isdigit() else (names.index(want) if want in names else None)
68
- if idx is None or not 0 <= idx < len(names):
69
- raise SymbolError(f"{decl} has no binder {want!r} (it has {', '.join(names)})")
70
- target = {"decl": decl, "var": idx} if var is not None else \
71
- {"decl": decl, "binder": idx, "path": "type"}
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)