prove: add marqdo prove (P0 emit/audit + P1 claim tables & check --proof)
Language layer (ADR 0010): - claim tables (定理|结论|前提|策略) parsed before first executable statement, extracted into Function.claims, removed from body - check --proof (default off): proof.claim_malformed / claim_ambiguous / claim_misplaced / claim_duplicate / claim_unknown_symbol / claim_unsupported / name_shadow Runtime layer (src/prove/): - ir.rs: Plan IR with stable hand-rolled JSON (schema 1) - lower.rs: subset acceptance (proof.while / proof.recursion / proof.dynamic_call), inlining for straight-line pure callees, opaque ops with effect labels, --allow-opaque whole-function downgrade - types.rs: literal-driven inference + branch confluence (proof.type_mismatch, exit 1) - emit.rs: deterministic Lean emission (Val × List Op, continuation style, -- mq: line:col anchors, «…» for dotted idents, theorem scaffolds from claims with unfold/split script) - mod.rs: prove/emit/audit/clean commands, Verdict taxonomy (error > unproved > rejected > unverified > checked > proved), exit codes 0/1/2 per design §3.3 Tests: tests/prove.rs 19 integration cases (no Lean required) + module unit tests; full suite stays green except the 3 documented env-limited failures. Docs: doc/design/prove-cli.md (§12 records deviations: result.ok/error vs drafted success/failure, Val-based run at P1, op arity, opaque effect label), doc/roadmap/prove.md, doc/adr/0010. Env fixes carried in: scratch dirs in test helpers honor CARGO_TARGET_DIR (needed on this machine's read-only target/debug).
This commit is contained in:
1 parent
6d6f580d24
commit
a11b347659
19 files changed
+6021
-13
No files matched your search
+166
-3
@@ -218,6 +218,10 @@ enum Commands {
|
||||
/// Parse an unmarked file with the legacy grammar for migration review.
|
||||
#[arg(long)]
|
||||
legacy_markup: bool,
|
||||
|
||||
/// Validate theorem tables (ADR 0010; 默认关): shape, symbols, shadowing
|
||||
#[arg(long)]
|
||||
proof: bool,
|
||||
},
|
||||
/// Occlusion label queries: pending stubs (built-in words) or keyword search
|
||||
Labels {
|
||||
@@ -495,6 +499,81 @@ enum Commands {
|
||||
#[command(subcommand)]
|
||||
action: WasmAction,
|
||||
},
|
||||
/// Compile SKILL orchestration to Lean 4 and (P1+) prove theorems (推荐但不强制)
|
||||
Prove {
|
||||
/// Action (default: emit + report)
|
||||
#[command(subcommand)]
|
||||
action: Option<ProveAction>,
|
||||
|
||||
/// Program path (.mq.md; default ./index.mq.md)
|
||||
#[arg(value_name = "FILE")]
|
||||
file: Option<PathBuf>,
|
||||
|
||||
/// One JSON object on stdout (agent-facing stable contract)
|
||||
#[arg(long)]
|
||||
json: bool,
|
||||
|
||||
/// Only lower/emit these functions (display path, repeatable)
|
||||
#[arg(long = "only", value_name = "FN")]
|
||||
only: Vec<String>,
|
||||
|
||||
/// Output dir for emit (default .marqdo/prove/<key>/)
|
||||
#[arg(long = "emit", short = 'o', value_name = "DIR")]
|
||||
emit_dir: Option<PathBuf>,
|
||||
|
||||
/// Don't write artifacts; report only
|
||||
#[arg(long)]
|
||||
report_only: bool,
|
||||
|
||||
/// Downgrade this function wholesale to one opaque op (repeatable)
|
||||
#[arg(long = "allow-opaque", value_name = "FN")]
|
||||
allow_opaque: Vec<String>,
|
||||
|
||||
/// Type inference is strict by default; this relaxes to Val (weaker proofs)
|
||||
#[arg(long = "no-strict-types")]
|
||||
no_strict_types: bool,
|
||||
|
||||
/// CI strict mode: unjudged statuses exit 2 (P1+)
|
||||
#[arg(long)]
|
||||
require_lean: bool,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
enum ProveAction {
|
||||
/// Generate deterministic Lean module + plan.json (no judging)
|
||||
Emit {
|
||||
#[arg(value_name = "FILE")]
|
||||
file: Option<PathBuf>,
|
||||
#[arg(long = "emit", short = 'o', value_name = "DIR")]
|
||||
emit_dir: Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
json: bool,
|
||||
#[arg(long = "only", value_name = "FN")]
|
||||
only: Vec<String>,
|
||||
#[arg(long = "allow-opaque", value_name = "FN")]
|
||||
allow_opaque: Vec<String>,
|
||||
#[arg(long = "no-strict-types")]
|
||||
no_strict_types: bool,
|
||||
},
|
||||
/// Report inline/opaque/rejected classification (no judging)
|
||||
Audit {
|
||||
#[arg(value_name = "FILE")]
|
||||
file: Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
json: bool,
|
||||
#[arg(long = "only", value_name = "FN")]
|
||||
only: Vec<String>,
|
||||
#[arg(long = "allow-opaque", value_name = "FN")]
|
||||
allow_opaque: Vec<String>,
|
||||
#[arg(long = "no-strict-types")]
|
||||
no_strict_types: bool,
|
||||
},
|
||||
/// Delete .marqdo/prove caches and certificates
|
||||
Clean {
|
||||
#[arg(long)]
|
||||
json: bool,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
@@ -656,7 +735,9 @@ fn main() -> ExitCode {
|
||||
let cli = Cli::parse();
|
||||
let json_errors = matches!(
|
||||
&cli.command,
|
||||
Commands::Run { json: true, .. } | Commands::Check { json: true, .. }
|
||||
Commands::Run { json: true, .. }
|
||||
| Commands::Check { json: true, .. }
|
||||
| Commands::Prove { json: true, .. }
|
||||
);
|
||||
match try_main(cli) {
|
||||
Ok(code) => ExitCode::from(code as u8),
|
||||
@@ -958,13 +1039,14 @@ fn try_main(cli: Cli) -> Result<i32> {
|
||||
implicit_labels,
|
||||
narrative_ratio,
|
||||
legacy_markup,
|
||||
proof,
|
||||
} => {
|
||||
let mut diags = if legacy_markup {
|
||||
marqdo::parse::expr::with_markup(marqdo::parse::expr::Markup::Classic, || {
|
||||
marqdo::check::check_path_opts(&file, implicit_labels)
|
||||
marqdo::check::check_path_opts(&file, implicit_labels, proof)
|
||||
})?
|
||||
} else {
|
||||
marqdo::check::check_path_opts(&file, implicit_labels)?
|
||||
marqdo::check::check_path_opts(&file, implicit_labels, proof)?
|
||||
};
|
||||
if narrative_ratio {
|
||||
diags.extend(marqdo::narrative_ratio::check_file(&file)?);
|
||||
@@ -989,6 +1071,87 @@ fn try_main(cli: Cli) -> Result<i32> {
|
||||
}
|
||||
Ok(errors.min(1))
|
||||
}
|
||||
Commands::Prove {
|
||||
action,
|
||||
file,
|
||||
json,
|
||||
only,
|
||||
emit_dir,
|
||||
report_only,
|
||||
allow_opaque,
|
||||
no_strict_types,
|
||||
require_lean,
|
||||
} => {
|
||||
// 子命令参数覆盖顶层默认;默认动作 = emit + 报告。
|
||||
let (file, action_json, action_emit, action_only, action_opaque, action_relax) =
|
||||
match &action {
|
||||
Some(ProveAction::Emit {
|
||||
file,
|
||||
emit_dir,
|
||||
json,
|
||||
only,
|
||||
allow_opaque,
|
||||
no_strict_types,
|
||||
}) => (
|
||||
file.clone(),
|
||||
*json,
|
||||
Some(emit_dir.clone()),
|
||||
only.clone(),
|
||||
allow_opaque.clone(),
|
||||
*no_strict_types,
|
||||
),
|
||||
Some(ProveAction::Audit {
|
||||
file,
|
||||
json,
|
||||
only,
|
||||
allow_opaque,
|
||||
no_strict_types,
|
||||
}) => (
|
||||
file.clone(),
|
||||
*json,
|
||||
None,
|
||||
only.clone(),
|
||||
allow_opaque.clone(),
|
||||
*no_strict_types,
|
||||
),
|
||||
Some(ProveAction::Clean { json }) => {
|
||||
let removed = marqdo::prove::clean()?;
|
||||
if *json {
|
||||
println!("{{\"ok\":true,\"removed\":{removed}}}");
|
||||
} else {
|
||||
println!("prove clean: 已删除 {removed} 项(.marqdo/prove)");
|
||||
}
|
||||
return Ok(0);
|
||||
}
|
||||
None => (file.clone(), false, Some(emit_dir.clone()), only.clone(), allow_opaque.clone(), no_strict_types),
|
||||
};
|
||||
let file = file.unwrap_or_else(|| PathBuf::from("index.mq.md"));
|
||||
// emit 目标:显式 --emit 优先;None → mod.rs 用默认 `.marqdo/prove/<key8>`。
|
||||
// audit 永不写盘;默认动作受 --report-only 控制;emit 子命令总是写盘。
|
||||
let emit_target = action_emit.flatten();
|
||||
let report_only = matches!(action, Some(ProveAction::Audit { .. }))
|
||||
|| (action.is_none() && report_only);
|
||||
let opts = marqdo::prove::ProveOptions {
|
||||
entry: None,
|
||||
only: action_only,
|
||||
allow_opaque: action_opaque,
|
||||
emit_dir: emit_target,
|
||||
strict_types: !action_relax,
|
||||
require_lean,
|
||||
report_only,
|
||||
};
|
||||
let report = marqdo::prove::prove_path(&file, &opts)?;
|
||||
for d in &report.diagnostics {
|
||||
// 诊断走 stderr(stdout 只放结果/报告)。
|
||||
eprintln!("{}", d.format_message());
|
||||
}
|
||||
if json || action_json {
|
||||
println!("{}", report.to_json());
|
||||
} else {
|
||||
print!("{}", report.to_text());
|
||||
}
|
||||
Ok(report.status.exit_code(require_lean))
|
||||
}
|
||||
Commands::Labels {
|
||||
paths,
|
||||
grep,
|
||||
|
||||
Reference in new issue
Block a user