moon_snapvault

    Local incremental snapshots, verified restore and recovery

    snapvault
    cli
    moonbit
    Download zip
    Author
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    18 days ago
    Downloads
    211

    #Moon SnapVault

    Content-addressed snapshots, implemented in MoonBit with a JSON CLI and reusable library API.

    • Repository: https://github.com/yyqdbngt/moon-snapvault
    • Package: yyqdbngt/moon_snapvault@0.2.0
    • License: Apache-2.0
    • Release scope: 0.1.0 initial implementation. The broader competition proposal in docs/proposal.md is a reference design, not a claim that every planned capability is implemented.

    #Implemented

    SHA-256 object identities; byte or UTF-8 text inputs; deduplicated content stores; manifest checksums; path/case/file-directory collision checks; incremental change reports and new-content statistics; full object integrity audits; verified restore plans. scripts/filesystem.mjs creates snapshots from real directories and restores real files.

    #Build and run

    Use MoonBit and Node.js 24. The core library supports JS, wasm, wasm-gc and native; the filesystem/HTTP/process CLI is JS only.

    moon update moon build --target js moon run cmd/main --target js -- examples/scenario-1.json node _build/js/debug/build/cmd/main/main.js examples/scenario-1.json

    Pass - to read a UTF-8 JSON request from stdin. A single request must be at most 16 MiB. Successful requests print one JSON result; invalid requests exit nonzero. The host runner is a separate process and does not edit the input request file.

    #Library use

    moon add yyqdbngt/moon_snapvault@0.2.0

    In the consumer's moon.pkg:

    import {
    "yyqdbngt/moon_snapvault" @engine,
    "moonbitlang/core/json",
    }

    fn example(request : Json) -> Json raise {
    @engine.execute(request)
    }

    execute(Json) -> Json raise is the standard JSON boundary. from_json, Value::to_json, and run(Value) -> Value raise provide a typed semantic value interface. Object ordering is not significant; numeric values use finite Double. Public domain functions are listed in pkg.generated.mbti.

    #Tests

    moon test --target js moon test --target wasm moon test --target wasm-gc moon test --target native # requires a C compiler moon build --target js node scripts/check.mjs python -B scripts/reference.py node scripts/integration.mjs

    There are 11 checked fixture cases in tests/cases.json, executed both in MoonBit white-box tests and through the actual Node CLI. Independent reference checks use Python's standard library or separately written algorithms. Fixtures are synthetic and are not presented as production adoption evidence. See input and output examples and current boundaries.

    #Current boundaries

    Each JSON snapshot is self contained, even when previous content is unchanged; new_object_bytes is a content statistic, not the physical archive size saved. The host adapter caps a backup at 1 MiB of source bytes; the core JSON CLI caps input at 16 MiB. Regular files only: no symlinks, empty-directory preservation, timestamps, ACLs or special files. Restore requires a new directory and validates all bytes first. A failed write retains the new partial directory for inspection. Designed for trusted local directories; concurrent hostile filesystem changes are not isolated. Manifests are integrity checked, not authenticated/encrypted.

    See source and dependency attribution. This release does not establish competition eligibility or organizer acceptance.

    #2026-10-18 follow-up

    新增 retention,对给定自包含快照及保留 ID 集合验证清单、引用对象和未引用对象,再计算共享对象可达性、可回收对象及字节数。默认保留所有给定快照;未知或重复保留 ID、损坏内容均拒绝。修复清单文件模式校验,避免重算校验和后夹带非法权限字段。

    只生成计划,不删除任何文件。可回收范围仅限输入中提供的对象,不包含未提供的外部仓库;自包含快照的逻辑对象统计不等同于实际磁盘节省量,宿主备份的 1 MiB 上限仍保留。

    Repository release: 0.2.0; installable MoonCakes module: yyqdbngt/moon_snapvault@0.2.0. Earlier repository 1.0.0 labels are retained as history; the module uses the registry-compatible zero-major sequence.

    Current source contains 13 MoonBit test declarations and 11 CLI fixtures (generated fixture tests are included in the declaration count). Run python -B scripts/followup_reference.py for independent follow-up oracles and examples/followup-20261018.json for the new scenario.

    InputError

    pub(all) suberror InputError {
    InputError(String)
    } derive(Eq, Show)

    Value

    pub(all) enum Value {
    Null
    Bool(Bool)
    Number(Double)
    String(String)
    Array(Array[Value])
    Object(Map[String, Value])
    } derive(Eq,
    Debug
    )

    Value::stringify

    fn Value::stringify(self : Value) -> String

    Value::to_json

    fn Value::to_json(self : Value) -> Json

    audit_snapshot

    fn audit_snapshot(snapshot : Value) -> Value raise

    create_snapshot

    fn create_snapshot(source : Array[Value], previous? : Value) -> Value raise

    diff_snapshots

    fn diff_snapshots(old : Value, new : Value) -> Value raise

    digest

    fn digest(bytes : Bytes) -> String

    execute

    fn execute(request : Json) -> Json raise

    from_json

    fn from_json(value : Json) -> Value

    retention_plan

    fn retention_plan(request : Value) -> Value raise

    run

    fn run(request : Value) -> Value raise

    safe_path

    fn safe_path(path : String) -> Bool