feat: land superpaper v1 notes scaffold

Add the ledger schema, class router, lint codes, ingest/build
pipeline, and three work-tree examples: align derivation,
superfig delegation, and supertensor delegation.
This commit is contained in:
dela
2026-08-17 10:01:30 +08:00
parent c2bec6f55a
commit 3a322aa8dc
89 changed files with 3522 additions and 11 deletions
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Raster one ledger figure from paper.pdf via pdftoppm. crop_bbox is 200 dpi page pixels.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
WORK=""
FID=""
while [[ $# -gt 0 ]]; do
case "$1" in
--work|--out) WORK="$2"; shift 2 ;;
--id) FID="$2"; shift 2 ;;
*) echo "usage: screenshot.sh --work DIR --id F2" >&2; exit 2 ;;
esac
done
[[ -n "$WORK" && -n "$FID" ]] || { echo "need --work and --id" >&2; exit 2; }
"$ROOT/scripts/python" - "$WORK" "$FID" <<'PY'
import sys, tempfile, subprocess, shutil
from pathlib import Path
import yaml
work = Path(sys.argv[1])
fid = sys.argv[2]
ledger = yaml.safe_load((work / "ledger.yaml").read_text())
fig = next((f for f in (ledger.get("figures") or []) if f.get("id") == fid), None)
if fig is None:
sys.exit(f"no figure {fid}")
pages = fig.get("source_pages") or []
if not pages:
sys.exit("source_pages required")
n = int(pages[0])
pdf = work / "source" / "paper.pdf"
if not pdf.is_file():
sys.exit(f"missing {pdf}")
dest_dir = work / "notes" / "figures" / fid
dest_dir.mkdir(parents=True, exist_ok=True)
dest = dest_dir / "orig.png"
bbox = fig.get("crop_bbox")
with tempfile.TemporaryDirectory() as td:
prefix = Path(td) / "pg"
subprocess.run(
["pdftoppm", "-png", "-r", "200", "-f", str(n), "-l", str(n), str(pdf), str(prefix)],
check=True,
)
produced = sorted(Path(td).glob("pg*.png"))
if not produced:
sys.exit("pdftoppm produced no page")
page = produced[0]
if bbox is None:
shutil.copy2(page, dest)
else:
if shutil.which("magick") is None:
sys.exit("crop_bbox set but magick is missing")
x0, y0, x1, y1 = bbox
w, h = int(x1 - x0), int(y1 - y0)
subprocess.run(
["magick", str(page), "-crop", f"{w}x{h}+{int(x0)}+{int(y0)}", "+repage", str(dest)],
check=True,
)
print(dest)
PY