Finite-domain counterfactual planner that certifies minimum-cost decision flips
moon add yourenA1108/flipspec@0.1.1git clone https://github.com/yourenA1108/flipspec.git
cd flipspec
moon check
moon build
moon testspec release-readiness
feature coverage = 72 in [72, 80, 90] cost 2
feature flaky = true in [true, false] cost 4
feature region = "cn" in ["cn", "global"] cost 3
feature signed = true in [true] locked
goal coverage >= 80 and not flaky and region == "global" and signedlet source =
#|spec gate
#|feature coverage = 72 in [72, 80, 90] cost 2
#|feature signed = true in [true] locked
#|goal coverage >= 80 and signed
match @flipspec.parse(source) {
Err(error) => println(error.render())
Ok(model) => {
println(model.evaluate().trace.to_text())
match model.plan() {
Ok(plan) => println(plan.to_markdown())
Err(errors) => println("invalid model: \{errors.length()} error(s)")
}
}
}# 解释当前决定并打印最低代价修复方案
moon run cmd/main
# 机器可读输出
moon run cmd/main -- --json
# Mermaid 解释图
moon run cmd/main -- --mermaid
# 单变量敏感性探测
moon run cmd/main -- --probe
# 最小性证书:证明示例中的最低代价方案来自完整搜索
moon run cmd/main -- --certificate
moon run cmd/main -- --certificate --json
# 预算曲线、模型画像和修复组合分析
moon run cmd/main -- --budget
moon run cmd/main -- --profile
moon run cmd/main -- --portfolio| 能力 | 主要 API | 说明 |
|---|---|---|
| DSL 解析 | parse | 带行列号和稳定错误码的词法、语法与模型校验 |
| 三值求值 | evaluate、Policy::evaluate | Yes、No、Unknown 的 Kleene 逻辑 |
| 解释 | Trace::to_text、blocking_leaves | 递归原因树与阻断条件前沿 |
| 反事实规划 | Policy::plan | 有界穷举、代价排序、支配方案消除 |
| 局部敏感性 | Policy::probe | 测试每个单变量修改是否翻转结果 |
| 决策面 | Policy::decision_table | 枚举可行组合,支持显式行数上限 |
| 表达式工具 | stats、simplify、to_nnf、substitute | 结构指标、等价化简和部分求值 |
| 批量回归 | evaluate_scenarios、diff_environments | 比较命名场景与当前基线 |
| 全局影响度 | Policy::impact_report | 在决策面上统计每个特征改变结果的次数 |
| 模型检查 | Policy::lint | 未使用特征、重复域值、恒真或永不为真等提示 |
| 修复复核 | Policy::verify_repair | 复核外部修复的域、锁定、成本、新鲜度和结果 |
| 最小性证书 | Plan::certify、Policy::search_space_size | 记录可行赋值总数、求值数、截断状态和最低代价是否已被穷尽搜索确认 |
| 预算曲线 | Policy::budget_report | 统计不同预算下的可达赋值、目标赋值与最低成功预算 |
| 模型画像 | Policy::profile | 汇总搜索空间、表达式复杂度、特征状态和可维护性信号 |
| 修复组合分析 | Plan::portfolio | 找出所有候选修复的共识特征、替代值和变更负担 |
| 导出 | to_markdown、to_json、to_mermaid | 零第三方运行时依赖 |
| 往返编辑 | Policy::to_source | 程序化模型序列化为可再次解析的 DSL |
moon check
moon build
moon test
moon run cmd/main
moon run cmd/main -- --json
moon run cmd/main -- --certificate
moon run cmd/main -- --budget
moon publish --dry-run.
├── model.mbt # 数据模型、三值逻辑与模型校验
├── lexer.mbt # 带位置的 DSL 词法分析
├── parser.mbt # 递归下降解析器
├── evaluate.mbt # 求值与解释树
├── planner.mbt # 反事实搜索、排序、敏感性探测
├── analyze.mbt # 阻断条件、决策表、DSL 序列化
├── transform.mbt # 表达式变换、结构指标与模型 lint
├── batch.mbt # 批量场景回归和环境差异
├── budget.mbt # 预算曲线和最低成功预算分析
├── impact.mbt # 全决策面特征影响度
├── profile.mbt # 模型画像、搜索规模和特征可维护性摘要
├── portfolio.mbt # 修复组合分析和共识特征提取
├── verify.mbt # 外部修复方案一致性复核
├── report.mbt # Markdown / JSON / Mermaid 导出
├── cmd/main # 可运行演示 CLI
├── flipspec_test.mbt # 黑盒行为测试
├── flipspec_wbtest.mbt # 内部不变量测试
├── docs # 语言、设计、调研、专项自查与发布说明
└── .github/workflows # 持续集成pub(all) struct BatchResult {
policy_name : String
baseline : Truth
scenarios : Array[ScenarioResult]
} derive(Eq, Debug)pub(all) struct DecisionTable {
policy_name : String
rows : Array[DecisionRow]
combinations : Int
truncated : Bool
} derive(Eq, Debug)pub(all) struct ImpactReport {
policy_name : String
impacts : Array[FeatureImpact]
source_rows : Int
truncated : Bool
} derive(Eq, Debug)pub(all) struct LintFinding {
code : String
severity : LintSeverity
message : String
feature : String?
} derive(Eq, Debug)pub(all) struct ModelProfile {
policy_name : String
features : Array[FeatureProfile]
goal_variables : Array[String]
expression_nodes : Int
expression_depth : Int
comparisons : Int
mutable_features : Int
locked_features : Int
zero_cost_mutable : Int
singleton_domains : Int
duplicate_domain_values : Int
search_space : Int
} derive(Eq, Debug)fn Policy::budget_report(self : Policy, max_budget? : Int, max_evaluations? : Int) -> Result[BudgetReport, Diagnostic]pub(all) struct RepairPortfolio {
policy_name : String
baseline : Truth
target : Truth
repair_count : Int
cheapest_cost : Int
most_expensive_cost : Int
total_changes : Int
average_changes : Int
consensus_features : Array[String]
optional_features : Array[String]
usages : Array[RepairFeatureUsage]
} derive(Eq, Debug)pub(all) struct RepairVerification {
valid : Bool
diagnostics : Array[Diagnostic]
outcome : Truth
computed_cost : Int
} derive(Eq, Debug)Install
Download zipFinite-domain counterfactual planner that certifies minimum-cost decision flips