"""Build static English reading pages from the research Markdown documents.""" import html import json import re import subprocess from pathlib import Path from urllib.parse import urlsplit from bs4 import BeautifulSoup from markdown_it import MarkdownIt ROOT = Path(__file__).resolve().parent.parent DOCS = ROOT / "outputs/cliff_realistic_dense_v1" SITE = ROOT / "deployments/cloudflare/site" DEST = SITE / "materials" HF = "https://huggingface.co/datasets/0721alex/a-plan-is-not-a-path" PACK = HF + "/resolve/main/outputs/english_research_pack.zip?download=true" PAGES = [ ("submission", "submission_en.md", "Application", "The question and the study", "Personal experience, a systematic evaluation and proposals for better LLM assistance.", "01"), ("methods", "methods_and_results_en.md", "Methods & results", "Methods and complete results", "The pinned checkpoint, full experimental settings, every cash level and reproduction commands.", "02"), ("theory", "theory_and_improvement_en.md", "Theory & improvements", "From diagnosis to better planning", "The economic mechanism and specific proposals for data, supervision and institutional support.", "03"), ("sources", "source_and_development_en.md", "Sources & development", "Sources and development history", "Published references, synthetic assumptions and every stage of the experiment's development.", "04"), ("data", "data_guide_en.md", "Data guide", "Inside the evaluation data", "A guide to the original records, reading copies, fields and reproduction workflow.", "05"), ("example", "example_task_en.md", "Example task", "The task, in full", "Read all six notices for one saved request, with the exact amounts, dates and funding conditions.", "06"), ("essay", "essay_en.md", "Full essay", "The full research essay", "The extended account, interactive-study captions and complete academic references.", "07"), ] BY_FILE = {p[1]: p[0] for p in PAGES} MARKDOWN = MarkdownIt("commonmark", {"html": True}).enable("table") def clean_source(text): return text.split("", 1)[-1].lstrip() def render_math(text): expressions = [] def take(match): expr = match.group(1) or match.group(2) expressions.append({"tex": expr.strip(), "display": match.group(1) is not None}) return f"
MATHTOKEN{len(expressions)-1}
" if match.group(1) else f"MATHTOKEN{len(expressions)-1}" text = re.sub(r"\$\$(.*?)\$\$|\$([^$\n]+)\$", take, text, flags=re.S) if not expressions: return text js = "const fs=require('fs'), k=require('./code/vendor/katex.cjs');process.stdout.write(JSON.stringify(JSON.parse(fs.readFileSync(0,'utf8')).map(e=>k.renderToString(e.tex,{output:'mathml',displayMode:e.display,throwOnError:true}))));" result = subprocess.run(["node", "-e", js], input=json.dumps(expressions), text=True, capture_output=True, cwd=ROOT, check=True) for i, rendered in reversed(list(enumerate(json.loads(result.stdout)))): text = text.replace(f"MATHTOKEN{i}", rendered) return text def fix_link(href): if href.startswith(("https:", "http:", "#", "mailto:")): return href part = urlsplit(href) name = Path(part.path).name if name in BY_FILE: return BY_FILE[name] + ".html" + ("#" + part.fragment if part.fragment else "") if name == "report.pdf": return "../assets/report.pdf" if part.path.startswith("figures_en/"): return "../assets/figures/" + Path(name).stem + ".svg" local = (DOCS / part.path).resolve() relative = local.relative_to(ROOT).as_posix() kind = "tree" if local.is_dir() else "blob" if local.suffix in {".md", ".py", ".txt"} else "resolve" return HF + "/" + kind + "/main/" + relative + ("#" + part.fragment if part.fragment else "") def body_and_toc(text): text = re.sub(r"^# .+\n", "", clean_source(text), count=1) soup = BeautifulSoup(MARKDOWN.render(render_math(text)), "html.parser") toc = [] for heading in soup.select("h2, h3"): ident = re.sub(r"[^a-z0-9]+", "-", heading.get_text().lower()).strip("-") heading["id"] = heading.get("id", ident) if heading.name == "h2": toc.append((heading["id"], heading.get_text())) for tag in soup.select("a[href], img[src]"): attr = "href" if tag.name == "a" else "src" tag[attr] = fix_link(tag[attr]) for table in soup.select("table"): wrap = soup.new_tag("div", attrs={"class": "table-scroll", "tabindex": "0", "aria-label": "Scrollable data table"}) table.wrap(wrap) for image in soup.select("img"): image["loading"] = "lazy" figure = soup.new_tag("figure") image.wrap(figure) if image.get("alt"): caption = soup.new_tag("figcaption") caption.string = image["alt"] figure.append(caption) return str(soup), toc def shell(title, content, active="", description="Research documents and original experimental records."): links = "".join(f'{number}{label}' for slug, _, label, _, _, number in PAGES) return f'''{html.escape(title)} · A Plan Is Not a Path
A Plan Is Not a PathResearch library
{content} ''' def main(): DEST.mkdir(parents=True, exist_ok=True) cards = [] for i, (slug, filename, label, title, description, number) in enumerate(PAGES): body, toc = body_and_toc((DOCS / filename).read_text()) contents = "".join(f'{html.escape(text)}' for ident, text in toc) previous = PAGES[i-1] if i else None following = PAGES[i+1] if i+1 < len(PAGES) else None neighbours = (f'Previous← {previous[2]}' if previous else 'Collection← Research library') neighbours += f'Continue reading{following[2]} →' if following else 'ExploreInteractive study ↗' menu = "".join(f'{p[5]}{p[2]}' for p in PAGES) content = f'''

Research document / {number}

{title}

{description}

In this document
{body}
''' (DEST / (slug + ".html")).write_text(shell(title, content, slug, description)) cards.append(f'{number}↗

{label}

{description}

Read online Markdown available
') content = f'''

A Plan Is Not a Path / Research collection

Research
library.

The question, the evidence and the work behind it.
Research documents alongside the original experimental records.

Reading sequence

Inside the study

Begin with the application. Use the methods and source record to examine how the result was obtained.

{''.join(cards)}

Original experiment

504 responses.
Every response is available.

The evaluated prompts and original model prose are Chinese. English prompt copies and outcome records make all 504 tasks and scored results accessible; the original responses remain available alongside them.

The short paper

The study in five pages.

Methods, three figures, complete findings and development context in one report.

Open the paper ↗
The paper's first figure: promises, structural validity and execution across starting cash.
''' (DEST / "index.html").write_text(shell("Research library", content)) print(f"Built {len(PAGES)} English documents and the research-library index.") if __name__ == "__main__": main()