目录

MoonFlagKit

MoonFlagKit is a small MoonBit library for feature flags and progressive rollout decisions. It is meant for service demos, Wasm edge experiments, command-line tools, and runtime configuration prototypes that need predictable flag evaluation without pulling in a server or configuration platform.

Core contributor: 王正本人

The first version focuses on a compact decision engine:

  • boolean feature flags;
  • allowlist and denylist rules;
  • environment and attribute matching;
  • stable percentage rollout buckets;
  • readable decision explanations;
  • configuration parsing and diagnostics.

Why This Project

MoonBit examples are increasingly used in service-side and Wasm scenarios. These projects often need a simple way to turn features on for a few users, disable risky behavior quickly, or test a new code path in one environment first. MoonFlagKit provides the decision layer for that work. It deliberately does not implement a remote control plane, UI, database, or network protocol, so the core remains easy to embed and test.

Example

let flag : @moonflagkit.Flag = {
  name: "checkout_v2",
  enabled: true,
  default_enabled: false,
  rollout: 25,
  salt: "summer",
  rules: [
    @moonflagkit.Allow("ops-admin"),
    @moonflagkit.Deny("blocked-user"),
    @moonflagkit.When("environment", "prod"),
    @moonflagkit.When("country", "CN"),
  ],
}

let context : @moonflagkit.EvalContext = {
  subject: "alice",
  environment: "prod",
  attributes: [{ key: "country", value: "CN" }],
}

let decision = @moonflagkit.evaluate(flag, context)
println(@moonflagkit.explain(decision))

For a runnable demonstration:

moon run cmd/main

Public API

  • evaluate(flag, context) -> Decision
  • evaluate_all(flags, context) -> Array[Decision]
  • parse_flags(input) -> Result[Array[Flag], FlagError]
  • validate_flags(flags) -> Array[FlagDiagnostic]
  • bucket(key, salt) -> Int
  • explain(decision) -> String
  • format_error(err) -> String

Configuration Format

The parser accepts a small line-oriented format for demos and tests:

flag checkout_v2 enabled=true rollout=35 salt=summer
allow checkout_v2 ops-admin
deny checkout_v2 blocked-user
when checkout_v2 environment=prod
when checkout_v2 country=CN

The format is intentionally narrow in v0.1. A future version can add JSON, TOML, or OpenFeature-style providers while keeping the same evaluation model.

Competition Positioning

MoonFlagKit targets the mature engineering area of progressive delivery: feature switches, canary rollout, kill switches, and runtime decision explanation. The implementation has no external MoonBit dependencies and is covered by behavior tests. It is a new project direction with its own API, tests, documents, and demonstration program.

关于

MoonFlagKit 是一个面向 MoonBit 生态的轻量级功能开关与灰度发布决策引擎,提供布尔开关、白名单/黑名单、上下文条件、稳定百分比灰度、配置解析、诊断和 CLI 示例。

925.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号