Skip to content

feat: add wizard subcommand (unstructured input → markdown) - #27

Open
m-messer wants to merge 5 commits into
mathpixfrom
wizard-command
Open

feat: add wizard subcommand (unstructured input → markdown)#27
m-messer wants to merge 5 commits into
mathpixfrom
wizard-command

Conversation

@m-messer

@m-messer m-messer commented Sep 1, 2026

Copy link
Copy Markdown
Member

in2lambda wizard INPUT -o draft.md turns a PDF/docx/tex/md document into the #/## markdown the Markdown filter reads, for a human to review before in2lambda convert draft.md Markdown.

Commits on this branch

  • feat: add wizard subcommandwizard/run.py routes input through Mathpix (PDF) / pandoc (docx) / raw read, runs one LLM extraction pass, renders #/## markdown, echoes check_markdown() warnings, writes the file. wizard/extract.py: pydantic WizardSet/WizardQuestion/WizardPart + extract_set() via the OpenAI structured-output parse against OpenRouter (system prompt + one few-shot). to_markdown() renders the filter's contract. run.py imported lazily so the rest of the CLI works without the llm extra. docs/source/wizard.md + toctree, quickstart + README pointers.
  • feat: --name/-n for convert — optional set name; sanitised into a filesystem-safe slug for set_<slug>.json / <slug>/ / <slug>.zip, raw name kept in the JSON name field (what Lambda Feedback shows on import). Default unchanged (set).
  • feat: repair mangled LaTeX commands — structured-output models sometimes emit \text/\frac/\beta with a single backslash; \t/\f/\b/\r are valid JSON escapes so the backslash is swallowed and the field ends up with a bare control char glued to the command. extract_set now re-escapes any TAB/CR/FF/BS immediately followed by a letter. Newlines left as-is.
  • chore.gitignore (docs/_bt/, /e2e/); CI test matrix reduced to Python 3.11 (.github/workflows/test.yml; the commit is mislabelled "Updated gitignore").

Testing done

  • black --check ., isort, pydocstyle, full pytest --cov — green (93 passed, 92%; wizard/extract.py 100%).
  • Live end-to-end against OpenRouter (openai/gpt-4o-mini) for .tex, .md and .docx inputs: wizard → review → convert → valid set.zip. The \text→TAB corruption is fixed and verified on the real model output.

Known gaps / notes

  • PDF/Mathpix path (from feat: add Mathpix PDF extraction #26) still untested against the live service.
  • pyproject.toml keeps python = "^3.10" while CI now tests only 3.11.
  • Wizard extraction is non-deterministic (a question was dropped on one of two .tex runs) — hence the mandatory draft.md review step.

Stack (top): … ← mathpix ← wizard-command
Base: mathpix#26. Merges after the whole stack (#21#26).

🤖 Generated with Claude Code

m-messer and others added 5 commits August 31, 2026 12:39
`in2lambda wizard INPUT -o draft.md` turns a PDF/docx/tex/md document into
the #/## markdown the Markdown filter reads, for a human to review before
`in2lambda convert draft.md Markdown`.

- wizard/run.py: routes input through Mathpix (PDF) / pandoc (docx) / raw
  read, runs one LLM extraction pass, renders #/## markdown, echoes
  check_markdown() warnings, writes the file.
- wizard/extract.py: pydantic WizardSet/WizardQuestion/WizardPart +
  extract_set() via the OpenAI structured-output parse helper against
  OpenRouter, with a system prompt and one few-shot example. to_markdown()
  renders the contract Step 3's filter consumes.
- main.py: `wizard` command; run.py imported lazily so the rest of the CLI
  works without the llm extra.
- Root conftest.py skips the pydantic-dependent wizard modules from
  --doctest-modules on a bare install (CI runs --all-extras).
- docs/source/wizard.md + toctree, quickstart + README pointers.

Slimmed from conversion2025/converter.py on Summer2025: the line-number
extraction and the trim/dedupe/evaluate passes are left out of v1; prompt
shape informed by wizard/to_question.py on wxyang_hackathon.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017VXb8aZqgFBjoeuuddjW6r
- Extend `runner()` and `convert` CLI to accept an optional `--name` (`-n`) parameter for naming question sets.
- Sanitize `set_name` into a filesystem-safe "slug" for output paths.
- Update JSON generation to use the sanitized name in filenames (`set_<name>.json`) and directories.
- Add tests for named sets and update documentation to reflect the new functionality.
- Add `_demangle` function to restore LaTeX control words whose backslashes were lost to JSON un-escaping.
- Adjust `extract_set` to apply `_demangle` to question titles, text, solutions, and parts.
- Add test to verify proper handling of mangled LaTeX commands and preservation of newlines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant