-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlean.rs
More file actions
79 lines (66 loc) · 2.18 KB
/
lean.rs
File metadata and controls
79 lines (66 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// ─── Lean 4 ──────────────────────────────────────────────────────────
use super::{CompileContext, CompilerExtension, ExtensionPhase};
use crate::runtimes::lean::{self, LEAN_BASH_COMMANDS, LeanRuntimeConfig};
use anyhow::Result;
/// Lean 4 runtime extension.
///
/// Injects: network hosts (elan, lean-lang), bash commands (lean, lake,
/// elan), install steps (elan + toolchain), and a prompt supplement.
pub struct LeanExtension {
config: LeanRuntimeConfig,
}
impl LeanExtension {
pub fn new(config: LeanRuntimeConfig) -> Self {
Self { config }
}
}
impl CompilerExtension for LeanExtension {
fn name(&self) -> &str {
"Lean 4"
}
fn phase(&self) -> ExtensionPhase {
ExtensionPhase::Runtime
}
fn required_hosts(&self) -> Vec<String> {
vec!["lean".to_string()]
}
fn required_bash_commands(&self) -> Vec<String> {
LEAN_BASH_COMMANDS
.iter()
.map(|c| (*c).to_string())
.collect()
}
fn prompt_supplement(&self) -> Option<String> {
Some(
"\n\
---\n\
\n\
## Lean 4 Formal Verification\n\
\n\
Lean 4 is installed and available. Use `lean` to typecheck `.lean` files, \
`lake build` to build Lake projects, and `lake env printPaths` to inspect \
the toolchain. Lean files use the `.lean` extension.\n"
.to_string(),
)
}
fn prepare_steps(&self) -> Vec<String> {
vec![lean::generate_lean_install(&self.config)]
}
fn validate(&self, ctx: &CompileContext) -> Result<Vec<String>> {
let mut warnings = Vec::new();
let is_bash_disabled = ctx
.front_matter
.tools
.as_ref()
.and_then(|t| t.bash.as_ref())
.is_some_and(|cmds| cmds.is_empty());
if is_bash_disabled {
warnings.push(format!(
"Agent '{}' has runtimes.lean enabled but tools.bash is empty. \
Lean requires bash access (lean, lake, elan commands).",
ctx.agent_name
));
}
Ok(warnings)
}
}