Metadata-Version: 2.5
Name: math-scout
Version: 0.7.0
Summary: A multi-agent first-pass reader for mathematical papers.
Project-URL: Homepage, https://github.com/nidrissi/mathbox/tree/main/math-scout
Project-URL: Issues, https://github.com/nidrissi/mathbox/issues
Author: Najib Idrissi
License-Expression: MIT
License-File: LICENSE
Keywords: anthropic,latex,llm,mathematics,openai,peer-review
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Text Processing :: Markup :: LaTeX
Requires-Python: >=3.11
Requires-Dist: anthropic<3,>=1
Requires-Dist: markdown-it-py<5,>=3
Requires-Dist: openai<4,>=3.5
Requires-Dist: pydantic<3,>=2.13
Requires-Dist: rich<17,>=15
Description-Content-Type: text/markdown

# Math Scout

[![CI](https://github.com/nidrissi/mathbox/actions/workflows/math-scout-ci.yml/badge.svg)](https://github.com/nidrissi/mathbox/actions/workflows/math-scout-ci.yml)

A multi-agent pipeline that reviews mathematical papers written in LaTeX. It splits a
`.tex` file into sections, runs a set of specialised LLM-based reviewers over them — some
section by section, some over the whole paper — and synthesises a final referee report in
markdown. Anthropic and OpenAI models can be used separately or together.

> **Alpha software.** It works and it is useful, but interfaces, prompts, and output
> formats will change without notice, and there is no backwards-compatibility promise
> before 1.0. Please report what breaks.

## What it is, and what it isn't

It is a **first-pass reading aid**. It is good at the mechanical parts of refereeing:
spotting undefined notation, unstated hypotheses, gaps between "clearly" and the actual
argument, and passages that assume more than they say.

It is **not a referee**, and its output is not a referee report you can rely on. It will
miss real errors and it will confidently flag correct arguments as broken. Every issue it
raises needs a human to verify it before you act on it, and a clean report is not evidence
that a paper is correct. Treat it as a colleague who read the paper quickly, not as a
proof checker.

## Reviewers

| Agent | Tier | Thinks | Reads | Role |
|---|---|---|---|---|
| `FormalVerifier` | strong | yes | a section | Proof gaps, invalid inferences, missing hypotheses, load-bearing computations |
| `AdversarialSkeptic` | strong | yes | a section | Edge cases, brittle arguments, degenerate examples |
| `ExpositionReferee` | fast | no | a section | Readability, missing intuition, proof strategy clarity |
| `NotationAuditor` | fast | yes | the whole paper | Symbol consistency, convention drift, broken references |
| `ClaimAuditor` | strong | yes | the whole paper | Overclaiming: what the abstract promises against what the theorems prove |

Each lane receives the referee skill’s shared protocol and its own lane prompt.
Local passes read the unit and extracted global context in a fresh request.
Whole-paper passes also receive the section findings. The final referee reads
the full manuscript, source map, raw findings, coverage and any supplied prior
lead. It dispositions each finding and produces the report.

Extended thinking is enabled per reviewer, on the shape of the task rather than the tier.
Deciding whether a proof step actually follows, building a counterexample, or tracing
notation and dependencies across a whole paper is multi-step reasoning and benefits from
it. The section-scoped exposition pass is scanning and matching, so it runs without
thinking. The final referee thinks too: it weighs and prioritises every finding across the
whole paper, and runs only once per review.

## Requirements

- Python 3.11 or newer
- Credentials with credit for each provider you select (Anthropic and/or OpenAI)

## Install

With [uv](https://docs.astral.sh/uv/), no checkout needed:

```bash
uvx math-scout paper.tex --dry-run
```

Or from a clone:

```bash
git clone https://github.com/nidrissi/mathbox
cd mathbox/math-scout
uv sync
uv run math-scout paper.tex --dry-run
```

Math Scout 0.7.0 introduced the shared Mathbox review format. Its wheel
includes the shared referee resources.

## Credentials

Only providers selected by the resolved preset and model flags are initialized or
contacted. The default command still needs only Anthropic credentials.

For Anthropic, either export a key:

```bash
export ANTHROPIC_API_KEY=...
```

…or sign in once with the [Anthropic CLI](https://platform.claude.com/docs/en/api/sdks/cli)
and the stored profile is picked up automatically:

```bash
ant auth login
```

Don't pass the key inline on the command line — it ends up in your shell history.

For OpenAI, export an API key:

```bash
export OPENAI_API_KEY=...
```

The preflight checks each distinct selected model with its provider's free input-token
count endpoint before creating output or asking you to approve a paid run. Credential,
permission, and missing-model failures name the provider that rejected the check.

## Cost

**Start with `--dry-run`.** A full review makes one API call per section (or subsection,
with `--split subsection`) per section-scoped reviewer, one whole-paper call for each
paper-scoped reviewer, and one
final referee call. Every one of them reads at least a section and several read the whole
paper, so on a long paper it adds up to real money.

```bash
math-scout paper.tex --dry-run
```

This asks each selected provider for the exact input-token count of every dry-run request
and prints a cost estimate without sending a generation request. It reads the output
directory the way a real run would, so reviews a resume would reuse are not counted and
their stored findings are included in the requests that follow. The individual counts
are exact; the run total is still a lower bound while any reviewer call is pending,
because it excludes the findings those calls have yet to produce. Cost
estimates are optional metadata: a model with no trustworthy price on file still works
and is shown as `pricing unknown`.

The `astra-sol-luna` preset limits Astra to the single synthesis call. Its registered
standard rates are $10/M input tokens, $1/M cached input, $12.50/M cache writes, and
$50/M output. Requests above 272K input tokens use 2x input and cache rates and 1.5x
output rates for the full request; `--dry-run` applies those multipliers per call.

The output figures are the opposite — ceilings nobody reaches, since they assume every
call emits its full `--max-tokens`. Two are printed: one assuming no call truncates, and
one assuming every call truncates and is retried. Real spend lands well below the first.

Before a real run starts, the tool identifies the review directory and asks you to confirm.

### Splitting at subsections

By default the section passes read one `\section` at a time. If a paper's sections are
long, `--split subsection` hands them one `\subsection` at a time instead. Each call has
less to get through, so it is less likely to run out of `--max-tokens`. The trade-off
is that it sees less of the surrounding argument. A section with no subsections is still
reviewed whole. A section's lead-in is a separate unit. A heading-only lead-in is recorded as skipped. The whole-paper passes and the
final referee are unaffected. Try `--dry-run` at both levels to compare call counts.

## Privacy

Running this **sends the full text of your paper to every API provider selected by your
model flags**. In a mixed run, both Anthropic and OpenAI receive paper content. If the
paper is unpublished, under embargo, covered by a collaboration agreement, or contains
anything you are not free to disclose to a third party, decide deliberately. Consult the
selected providers' current privacy and data-usage terms before running it.

## Usage

```bash
math-scout paper.tex                          # review, with a confirmation prompt
math-scout paper.tex --output /tmp/review     # choose the output directory
math-scout paper.tex --dry-run                # token count + cost estimate only
math-scout paper.tex --yes                    # skip the prompt (needed in CI/scripts)
math-scout paper.tex --preset astra-sol-luna  # Astra final, Sol strong, Luna fast
math-scout paper.tex --preset sol-luna        # OpenAI Sol for strong, Luna for fast
math-scout paper.tex --preset opus-sonnet     # Anthropic Opus for strong, Sonnet for fast
math-scout paper.tex \
  --strong-model openai:gpt-6.1-sol \
  --fast-model anthropic:claude-sonnet-5-5 \
  --final-model openai:gpt-6-astra               # independent synthesis model
```

| Flag | Meaning |
|---|---|
| `--output DIR` | Where to write results (default: `<input_dir>/review/`) |
| `--prior-leads FILE` | Save a verbatim lead for the final referee |
| `--dry-run` | Count tokens and estimate cost; send no generation requests |
| `-y`, `--yes` | Skip the confirmation prompt. Required when stdin is not a terminal |
| `--preset NAME` | Select `astra-sol-luna`, `sol-luna`, or `opus-sonnet` |
| `--strong-model PROVIDER:MODEL` | Model for the three deep reviewers |
| `--fast-model PROVIDER:MODEL` | Model for the two lighter reviewers |
| `--final-model PROVIDER:MODEL` | Model for final synthesis (default: resolved strong model) |
| `--max-tokens N` | Output token limit per call (default 32000, maximum 64000) |
| `--effort LEVEL` | `low`, `medium`, `high`, `xhigh`, or `max` (default `high`) |
| `--split LEVEL` | Cut the paper at each `section` or each `subsection` for the section passes (default `section`) |
| `--version` | Print the version |

Exit codes: `0` success, or you declined at the confirmation prompt; `1` finished but
some reviewer calls failed; `2` bad configuration — missing provider credentials, an
unknown or unusable provider/model, nothing to review, or no terminal to confirm on
without `--yes`.

### Multi-file papers

`\input{...}` and `\include{...}` are resolved and inlined before chunking, relative to
the main file's directory and then the including file's. Missing, cyclic, dynamic and out-of-bound includes stop preparation before generation.
Snapshots retain original file/line locators, extracted context and all review units.

### Choosing providers, models, and effort

Defaults are `anthropic:claude-opus-5-5` for the strong tier and
`anthropic:claude-sonnet-5-5` for the fast tier. Final synthesis follows the resolved strong
model unless `--final-model` or a preset selects one independently. Every explicit model must use
`provider:model`; bare IDs are rejected. Use a preset to keep common combinations concise:

```bash
math-scout paper.tex --preset opus-sonnet
math-scout paper.tex --preset sol-luna
math-scout paper.tex --preset astra-sol-luna
math-scout paper.tex \
  --strong-model anthropic:claude-opus-4-7 \
  --fast-model anthropic:claude-sonnet-4-6
math-scout paper.tex \
  --strong-model openai:gpt-6.1-sol \
  --fast-model anthropic:claude-sonnet-5-5
```

The legacy presets set both tiers together: `opus-sonnet` resolves to
`anthropic:claude-opus-5-5` and `anthropic:claude-sonnet-5-5`, while `sol-luna` resolves to
`openai:gpt-6.1-sol` and `openai:gpt-6-luna`; their final referee follows the effective
strong model, including when `--strong-model` overrides the preset. `astra-sol-luna`
uses `openai:gpt-6-astra` for final synthesis, `openai:gpt-6.1-sol` for the strong tier,
and `openai:gpt-6-luna` for the fast tier. Each explicit flag replaces its corresponding
preset selection; for the legacy presets, the final model continues to follow the
resolved strong model. For example,
`--preset sol-luna --fast-model anthropic:claude-sonnet-5-5` is a concise mixed-provider
configuration. Reuse keys record the resolved qualified model IDs, not the preset name, so a
preset command and its fully explicit equivalent can resume the same run.

Other current options include `openai:gpt-6.1-terra`, `anthropic:claude-haiku-5-5`,
and `anthropic:claude-fable-5-1`. Capability and pricing metadata follow the official
[OpenAI model catalog](https://developers.openai.com/api/docs/models) and
[Claude model catalog](https://platform.claude.com/docs/en/models/overview).
Older registered models remain available through explicit flags.

**Output from an earlier release (with `state.json`, `chunks/` or `final_report.md`) is
never resumed.** Scout leaves that directory intact and prints the same command with a
fresh `--output` path; see [Review files and migration](#review-files-and-migration).
Within the current format, changing reviewer models or settings starts a new run under
`review/revisions/` instead of mixing findings from different models.

The final referee uses the independently resolved final model. Changing only
`--final-model` starts a new revision that reuses the stored reviewer passes and
synthesizes a new report. There are no per-reviewer model flags.

Capability validation is provider-specific. Known incompatible combinations are refused
before spending. Reasoning reviewers receive the selected effort. For an OpenAI reviewer
that does not reason, the adapter requests `none` where the model supports it, or omits
the reasoning field for known non-reasoning models. GPT-6 Astra, GPT-6.1 Sol, Claude
Opus 5.5, and Claude Fable 5.1 require reasoning, so they cannot serve the fast tier:
`ExpositionReferee` runs without up-front thinking. They work as strong or final models.
On Claude Sonnet 5.5, the adapter uses `between_tools` for this reviewer; without tools,
that mode returns text only.

`--effort` is the main cost and latency lever — it controls how much the models reason and
spend overall. `high` is the default; drop to `medium` or `low` on a long paper or a quick
pass, raise to `xhigh` or `max` on something that warrants it.

Two constraints are worth knowing:

- `--max-tokens` covers thinking *and* response text together. **It is headroom, not a
  budget to spend.** Unused budget costs nothing, but a call that runs out mid-answer is
  billed in full and returns nothing usable — so a cap set too low *causes* cost rather
  than limiting it. Lower it to save money and you will generally spend more. The default
  of 32000 leaves room for a deep reviewer to think its way through a long section; if you
  see truncation warnings, raise it rather than lowering it.
- Claude Sonnet 5.5 and Haiku 5.5 allow running without up-front thinking only at `high`
  effort or below. This includes the default fast model: `--effort xhigh` and
  `--effort max` require another fast model, such as `--fast-model openai:gpt-6-luna`.
  Incompatible combinations are refused before any request.

If a call does exhaust its budget, it is retried once at one provider-mapped `--effort`
level down when that produces a different request. A second truncation is a real failure.
An OpenAI non-reasoning call already sent with `effort=none`, for example, is not repeated
under a lower CLI label that would send the same request. Because a truncated call bills
in full, `--dry-run` reports a conservative retry ceiling.

### Resuming

Repeat the command after an interruption or a failed synthesis. Scout checks the
completed passes and their provider receipts before reuse. It retries failed and
partial passes. Whole-paper passes that depend on pending section findings run
again, followed by final synthesis; Scout reuses a stored whole-paper pass instead
when the section findings it would receive are unchanged. Use `--dry-run` to see the pending calls
and estimated cost. A dry run reads the manuscript and existing review and can
send text to the selected providers’ token-count endpoints.

The first snapshot lives in `review/` beside the manuscript. Source, split,
prompt or settings changes select a run in `review/revisions/`. Scout prints
the selected directory. A local pass can carry forward when its unit, context,
locators, prompt and execution settings match and the reviewer recorded its
checks as self-contained. Other dependencies require the original source-file
inventory. Whole-paper review and synthesis run again on a changed manuscript.

## Review files and migration

| Earlier Math Scout output | Shared review artifact |
|---|---|
| `chunks/` | Immutable `manifest.json`, `full-source.tex`, `sections/` and `context.json` |
| `reviews/` | `passes/<pass_id>.json` with evidence, settings and raw findings |
| `all_issues.json` | `findings.json` with raw issues and coverage for each lane |
| `final_report.md` | `report.md` and `reconciliation.json` with per-finding dispositions |

The new reader accepts runs produced by the independently installed referee skill.
Validate a completed prepared run offline with the installed Python interpreter.

```bash
python -m math_scout.referee_core.review_artifacts review
```

A legacy directory stays intact. The CLI prints a command with your original
options and a fresh output path. Historical `issues.jsonl` and `state.json`
remain evidence from the earlier pipeline. Historical reviews may lack the
inputs or reconciliation needed to credit them as new passes.

Provider response metadata and retry settings live in `response_metadata.jsonl`.
The `attempts/` directory preserves provider returns, including invalid synthesis
and truncations. Repeated synthesis preserves the preceding report, reconciliation
and coverage under `history/`. Prior leads supplied with `--prior-leads` are
recorded verbatim in `prior-leads.md` and kept out of blind lane inputs.

## Known limitations

The LaTeX reader expands literal includes within the main file’s directory.
Macro-generated structure, external graphics, bibliography files and external
theorems can require manual checking. The native referee skill supports
manual coverage of PDF and pasted manuscripts and can request specialist
checks from the host. API reviewers receive only the evidence in their request.

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md). Bug reports and papers that break the chunker are
especially welcome — [open an issue](https://github.com/nidrissi/mathbox/issues).

## License

MIT — see [LICENSE](LICENSE).
