# MoonEdit

> **Library · editor-core alpha.** Read the
> [product contract](docs/PRODUCT_CONTRACT.md) for the host boundary, current
> capabilities, limitations and MoonDesk integration gates.

Core document revisions are checked through `2147483647`: mutating edits and history traversal reject exhaustion atomically, while empty edits and empty undo/redo remain nonmutating successes.

> **Workspace API policy (WP04):** host work is returned as explicit effects. Close,
> load/reload, and save callbacks are accepted only for their exact identities; saves bind
> request plus revision and use strong host `FileVersion` CAS tokens. The first matching
> terminal callback wins. Watcher observations deferred across saves are all reconciled;
> any unknown or different token forces stale/conflict. Reload failure retains editable
> stale content. `TabSnapshot` and public array accessors return detached values.

> **Language API policy (WP05):** semantic-token, completion, and definition queries use typed wrappers; retained-response budget is aggregate across lanes and documents; accepted definitions are invalidated when their exact target document and revision is replaced, closed, or retired by reopen. Language verification passes **41/41** tests on wasm, wasm-gc, JavaScript, and native. See the [`WP05 language ledger`](docs/WP05_LANGUAGE_LEDGER.md).

MoonEdit is a host-independent editor foundation written in MoonBit. Its current layers provide a pure document core, audited in-memory workspace orchestration, and in-memory language-provider orchestration, including UTF-16 coordinates, atomic ordered edits, selections, revisions, dirty state, line indexing, and bounded undo/redo.

The [`moonedit.merge.v1` contract](docs/MERGE_CONTRACT.md) adds a deterministic
three-way merge with exact snapshot identities, SHA-256 evidence, structured
conflicts, stale-proposal rejection and separately human-accepted resolution
receipts. Workspace exposes exact `LoadMerge` and apply hooks without taking
over host persistence or UI.

I/O remains outside `core`; `surface` defines a read-only provider/viewer boundary for future Rabbita and moonbit-community/editor adapters. The project does not yet provide host LSP transport, persistence, or a UI.

```moonbit
let doc = @core.Document::new("hello")
```

WP04 verification passed **72 wasm**, **72 wasm-gc**, **73 JavaScript**, and **72 native** tests, plus all-target check, `moon info`, `moon fmt`, and `git diff --check`. See [`docs/WP04_IDENTITY_CONTRACTS.md`](docs/WP04_IDENTITY_CONTRACTS.md).

Current limitations: no persistence host adapter, no host merge UI, no
syntax-aware merge claim, and no large-file performance claim.

## Development

```sh
moon fmt
moon info
moon check --target all --warn-list +73
moon test --target all
```

Licensed under Apache-2.0.
