leanprover / leanprover/lean-beam

Support multi-command snippets in MCP lean_run_at

Open
#100 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lean
Stars
31
Forks
4
Avg merge
1d 13h
Merged PRs (30d)
12

Description

Current status

lean_run_at now reports a clear semantic failure for top-level command sequences:

runAtSupportsOneCommandOnly: command-mode runAt accepts exactly one Lean command...

That fixed the confusing raw expected end of input symptom and documents the current one-command contract. It is not the desired final behavior for this issue.

Requested behavior

Support complete Lean command sequences in command-mode lean_run_at at a source position. For example, this should execute as one speculative request:

def beamRunAtA : Nat := 1

def beamRunAtB : Nat := beamRunAtA

#check beamRunAtB

Later commands in the snippet should see earlier commands from the same snippet, while the request still behaves like an isolated runAt sandbox:

  • do not mutate the real document elaboration state
  • do not depend on side effects from previous requests
  • discard derived execution state after plain lean_run_at
  • for handle-storing variants, store the final command state after the sequence only when the API explicitly asks for a handle

Minimal reproduction

Create a clean module:

def beamRunAtBase : Nat := 0

A single command works:

{
  "tool": "lean_run_at",
  "arguments": {
    "path": "Liris/BeamRunAtRepro.lean",
    "line": 1,
    "character": 0,
    "text": "#check beamRunAtBase"
  }
}

A complete multi-command snippet currently fails with runAtSupportsOneCommandOnly:

{
  "tool": "lean_run_at",
  "arguments": {
    "path": "Liris/BeamRunAtRepro.lean",
    "line": 1,
    "character": 0,
    "text": "def beamRunAtA : Nat := 1\n\ndef beamRunAtB : Nat := beamRunAtA\n\n#check beamRunAtB"
  }
}

Relationship to batch runAt

This is separate from #101. Multi-command support lets one snippet elaborate as ordinary Lean command text. Batch runAt is still useful for several independent probes with per-item results.

Agent impact

This would reduce friction for common source-position probes such as declaring a helper and immediately checking a consumer, without writing scratch files or reconstructing context outside the real module.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the command-mode lean_run_at entry point and reproduce the failure with the minimal multi-command JSON request against Liris/BeamRunAtRepro.lean. Trace how command text and speculative state are handled, then verify that later commands see earlier ones, real document state remains unchanged, and plain requests discard derived state while handle variants retain only the final state.

Written by the indexing model from the issue text.

Assessment

Domain
api, developer-experience
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.