|
| 1 | +<!-- |
| 2 | +SPDX-FileCopyrightText: 2026 MesTTo |
| 3 | +SPDX-License-Identifier: MIT |
| 4 | +--> |
| 5 | + |
| 6 | +# Experimental features |
| 7 | + |
| 8 | +MeTTa TS ships in-progress work on a separate prerelease line before it reaches a stable release. This page explains what that line is, how to opt into it, and what it currently contains. |
| 9 | + |
| 10 | +## The two channels |
| 11 | + |
| 12 | +Every package publishes to one of two npm dist-tags: |
| 13 | + |
| 14 | +- `latest` is the stable line. A plain `npm install @metta-ts/core` installs it, and its API does not change under you within a major version. This is what you want for production. |
| 15 | +- `experimental` is the prerelease line. It carries features that are complete and tested but whose public surface may still change before they land in a stable release. Its versions carry an `-experimental.N` suffix, for example `1.2.0-experimental.0`. |
| 16 | + |
| 17 | +The stable line never depends on the experimental one, so installing stable is unaffected by anything here. |
| 18 | + |
| 19 | +## Installing the experimental line |
| 20 | + |
| 21 | +Opt in per package by asking for the tag: |
| 22 | + |
| 23 | +```bash |
| 24 | +npm install @metta-ts/core@experimental |
| 25 | +npm install @metta-ts/hyperon@experimental |
| 26 | +``` |
| 27 | + |
| 28 | +For a reproducible build, pin the exact version instead of the moving tag: |
| 29 | + |
| 30 | +```bash |
| 31 | +npm install @metta-ts/core@1.2.0-experimental.0 |
| 32 | +``` |
| 33 | + |
| 34 | +A plain install stays on stable: |
| 35 | + |
| 36 | +```bash |
| 37 | +npm install @metta-ts/core # resolves the latest tag |
| 38 | +``` |
| 39 | + |
| 40 | +## What to expect |
| 41 | + |
| 42 | +The experimental features work and are covered by the test suite, but treat them as a preview: |
| 43 | + |
| 44 | +- The API may change between experimental versions. Read the [release notes](https://github.com/MesTTo/MeTTa-TS/releases) before upgrading, and pin an exact version if you depend on the current shape. |
| 45 | +- The semantics of stable MeTTa evaluation are unchanged. The experimental line adds new surfaces; it does not alter how existing programs evaluate. |
| 46 | +- Feedback is the point. If something is awkward or missing, open an issue on [GitHub](https://github.com/MesTTo/MeTTa-TS/issues); this line exists so that the stable shape can be informed by real use. |
| 47 | + |
| 48 | +## What is in it now |
| 49 | + |
| 50 | +The current experimental line (`1.2.0-experimental.0`) contains: |
| 51 | + |
| 52 | +- **The Grounded V2 operation protocol.** A grounded operation can return an owned, pull-based stream of answers, each carrying its own binding delta and effects, rather than one eagerly collected array. The evaluator owns the stream and closes it exactly once, so a consumer that stops early stops the producer. |
| 53 | +- **Streaming operations on the runner.** `MeTTa.registerStreamingOperation` and `registerAsyncStreamingOperation` wrap that protocol for everyday use. |
| 54 | +- **Cursor streaming through interpreted evaluation.** A `metta`/`metta-thread` call and interpreted rule alternatives stream one answer per pull, so `once` over a large interpreted producer does one step and closes the tail. |
| 55 | +- **Minimal MeTTa runtime foundations.** Typed runtime foundations for the minimal machine: scoped variables and canonical persistent binding frames, binding capture and replay, coherent evaluation contexts with logical snapshots, explicit control semantics, resumable search cursors, and persistent branch worlds with bounded effect replay. |
| 56 | + |
| 57 | +## Streaming grounded operations |
| 58 | + |
| 59 | +The headline feature is streaming grounded operations. A normal grounded operation collects every result into an array before the evaluator sees any of them. A streaming operation hands the evaluator a generator instead, and the evaluator pulls one answer at a time. A consumer such as `once` then stops the producer rather than draining it. |
| 60 | + |
| 61 | +```ts |
| 62 | +// requires @metta-ts/hyperon@experimental |
| 63 | +import { MeTTa, ValueAtom } from "@metta-ts/hyperon"; |
| 64 | + |
| 65 | +const metta = new MeTTa(); |
| 66 | + |
| 67 | +metta.registerStreamingOperation("naturals", function* () { |
| 68 | + for (let n = 0; ; n += 1) yield ValueAtom(n); |
| 69 | +}); |
| 70 | + |
| 71 | +metta.run("!(once (naturals))")[0].map(String); // [ '0' ]: one pull, the infinite tail is closed |
| 72 | +``` |
| 73 | + |
| 74 | +An answer can also be an object `{ atom, bindings, effects }`. `bindings` gives values for variables that appear in the call's arguments, keyed by variable name, so an operation can bind caller variables per alternative. `effects` (add or remove an atom, bind a token) apply only when that answer's branch is accepted: |
| 75 | + |
| 76 | +```ts |
| 77 | +metta.registerStreamingOperation("digits-of", function* (args) { |
| 78 | + for (const ch of String(args[0])) |
| 79 | + yield { atom: args[1]!, bindings: { d: ValueAtom(Number(ch)) } }; |
| 80 | +}); |
| 81 | + |
| 82 | +metta.run("!(digits-of 305 $d)")[0].map(String); // [ '3', '0', '5' ] |
| 83 | +``` |
| 84 | + |
| 85 | +`registerAsyncStreamingOperation` is the asynchronous twin, for producers that await between answers (a paginated fetch, a database cursor). Its `signal` argument aborts when the evaluation is cancelled, so the producer stops requesting more as soon as the consumer stops pulling. |
| 86 | + |
| 87 | +The full protocol underneath, `registerGroundedOperationV2`, and its ownership, binding-delta, and effect rules are described in the [1.2.0-experimental.0 release notes](https://github.com/MesTTo/MeTTa-TS/releases/tag/v1.2.0-experimental.0) and the repository's `docs/minimal-metta-runtime.md`. |
| 88 | + |
| 89 | +## Where the work happens |
| 90 | + |
| 91 | +The experimental line is built on the [`experimental` branch](https://github.com/MesTTo/MeTTa-TS/tree/experimental) of the repository, and each prerelease is cut from there. The stable site you are reading tracks `main`; the experimental branch carries the same guide plus the detailed reference for the surfaces above. |
0 commit comments