Skip to content

Commit a4f547c

Browse files
committed
MeTTa TS 1.1.1
1 parent b042562 commit a4f547c

201 files changed

Lines changed: 9586 additions & 1114 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules/
22
dist/
33
*.tsbuildinfo
44
.DS_Store
5+
.npmrc
56
zod
67

78
# TypeDoc output (per-package)
@@ -10,7 +11,5 @@ packages/*/docs/
1011
# VitePress build output
1112
website/.vitepress/dist/
1213
website/.vitepress/cache/
13-
packages/node/bench/lib
14-
1514
# Local hyperon venv for the @metta-ts/py differential oracle (HYPERON_LIVE=1)
1615
.venv-hyperon/

README.md

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MeTTa TS
22

3-
A pure-TypeScript implementation of **MeTTa** (Meta Type Talk), the OpenCog Hyperon language. It runs anywhere TypeScript runs: the browser, Node, Deno, Bun, edge and serverless functions, and inside TypeScript-based AI agents. No native addons, no WASM, no Rust.
3+
A pure-TypeScript implementation of **MeTTa** (Meta Type Talk), the OpenCog Hyperon language. The core engine runs anywhere TypeScript runs: the browser, Node, Deno, Bun, edge and serverless functions, and inside TypeScript-based AI agents. No native addons, no required WASM, no Rust.
44

55
<p align="center">
66
<img src="website/public/recursion.gif" width="840" alt="The factorial (fact 5) reducing to 120, played side by side as a node graph and as nested blocks in MeTTaGrapher" />
@@ -21,7 +21,8 @@ Other packages, add as needed:
2121
npm install @metta-ts/hyperon # a Python-hyperon-style class API
2222
npm install @metta-ts/node # CLI + file import! + a parallel matcher
2323
npm install @metta-ts/browser # web entry + in-memory virtual file system
24-
npm install @metta-ts/py # call Python (py-call / py-atom) via pythonia
24+
npm install @metta-ts/py # optional Python interop: pythonia or Pyodide
25+
npm install @metta-ts/prolog # optional Prolog interop: SWI native or SWI-WASM
2526
```
2627

2728
For the command-line runner, install `@metta-ts/node` globally (or use `npx`):
@@ -158,6 +159,65 @@ db.call.fact(5); // [120]
158159
const factorial = db.import<[number], number>("fact"); // typed callable, factorial(6) === 720
159160
```
160161

162+
The eDSL also has dependency-free helper subpaths for optional host interop:
163+
`@metta-ts/edsl/py` builds `py-call`, `py-atom`, and collection forms, while
164+
`@metta-ts/edsl/prolog` builds `prolog-call`, `Predicate`, and
165+
`import_prolog_function`. These helpers only build atoms. You still opt into the
166+
runtime through `@metta-ts/py` or `@metta-ts/prolog`.
167+
168+
```ts
169+
import { vars } from "@metta-ts/edsl";
170+
import { pyCall } from "@metta-ts/edsl/py";
171+
import { prologCall } from "@metta-ts/edsl/prolog";
172+
173+
const { x } = vars();
174+
175+
pyCall("math.add", 40, 2); // (py-call (math.add 40 2))
176+
prologCall(["edge", "alice", x]); // (prolog-call (edge alice $x))
177+
```
178+
179+
## Python and Prolog interop
180+
181+
Host interop is explicit. A normal MeTTa run never loads Python or Prolog. When
182+
you pass a host adapter, MeTTa source can import host files and call them through
183+
ordinary MeTTa atoms.
184+
185+
Node:
186+
187+
```bash
188+
metta-ts --py program.metta # needs pythonia and python3
189+
metta-ts --prolog program.metta # needs swipl on PATH
190+
```
191+
192+
Browser:
193+
194+
```ts
195+
import { createBrowserRunner, createBrowserTextLoader } from "@metta-ts/browser/host";
196+
import { createPyodideInterop } from "@metta-ts/py/pyodide";
197+
import { createSwiWasmInterop } from "@metta-ts/prolog/swi-wasm";
198+
199+
const files = new Map([
200+
["math.py", "def add(a, b):\n return a + b\n"],
201+
["facts.pl", "edge(alice, bob).\nedge(alice, mars).\n"],
202+
]);
203+
const loadText = createBrowserTextLoader({ files, baseUrl: import.meta.url });
204+
const runner = createBrowserRunner({
205+
files,
206+
interops: [await createPyodideInterop({ loadText }), await createSwiWasmInterop({ loadText })],
207+
});
208+
209+
await runner.run(`
210+
!(import! &self "math.py")
211+
!(py-call (math.add 40 2))
212+
!(import! &self "facts.pl")
213+
!(prolog-call (edge alice $x))
214+
`);
215+
```
216+
217+
The Prolog surface follows PeTTa's `Predicate`, `callPredicate`, `prolog-call`,
218+
and `import_prolog_function` forms where they are independent of PeTTa's own
219+
evaluator. MeTTa TS does not add a PeTTa mode or a curry mode.
220+
161221
More runnable examples are in [`examples/`](examples/): [`quickstart.ts`](examples/quickstart.ts), [`grounded-ops.ts`](examples/grounded-ops.ts), [`async.ts`](examples/async.ts), [`edsl.ts`](examples/edsl.ts), plus `.metta` source files. Run one with `npx tsx examples/quickstart.ts`.
162222

163223
## Connecting to a Distributed AtomSpace
@@ -191,7 +251,10 @@ A faithful port of hyperon-experimental's minimal interpreter (the nondeterminis
191251

192252
Beyond the core: transactions, async evaluation, concurrency primitives (`par`, `race`, `once`, `hyperpose`, `with-mutex`), clause indexing that scales matching to millions of atoms, a flat interned knowledge base with a worker-thread parallel matcher, and a JavaScript interop layer (`js-atom`, `js-dot`, `js-list`, `js-dict`) that calls into the host runtime directly.
193253

194-
The whole thing is pure TypeScript. The core builds to a single ESM bundle (~23 KB gzipped) that runs in Node and the browser with no native addon and no WASM.
254+
The language engine is pure TypeScript. The core builds to a single ESM bundle
255+
(~23 KB gzipped) that runs in Node and the browser with no native addon and no
256+
required WASM. Optional host adapters are separate packages: Pyodide and
257+
SWI-WASM are only pulled into browser bundles that import their adapter subpaths.
195258

196259
```bash
197260
pnpm install
@@ -202,19 +265,20 @@ node packages/node/dist/cli.js examples/factorial.metta
202265

203266
## Packages
204267

205-
| Package | What it is |
206-
| --------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
207-
| [`@metta-ts/core`](packages/core) | The interpreter, parser, type system, and standard library. Zero platform dependencies. |
208-
| [`@metta-ts/hyperon`](packages/hyperon) | A TypeScript class API over the core, modeled on Python's `hyperon`. |
209-
| [`@metta-ts/edsl`](packages/edsl) | An ergonomic, typed eDSL: term builders, special-form combinators, and a tagged template. |
210-
| [`@metta-ts/node`](packages/node) | The `metta-ts` CLI, file `import!`, and a `SharedArrayBuffer` worker-thread parallel matcher. |
211-
| [`@metta-ts/browser`](packages/browser) | Browser entry point with an in-memory virtual file system for `import!`. |
212-
| [`@metta-ts/py`](packages/py) | Optional Python interop: PeTTa's `py-call` and Hyperon's `py-atom` over a caller-supplied pythonia bridge. |
213-
| [`@metta-ts/das-client`](packages/das-client) | Optional client to SingularityNET's Distributed AtomSpace via a Connect gateway. |
268+
| Package | What it is |
269+
| --------------------------------------------- | --------------------------------------------------------------------------------------------- |
270+
| [`@metta-ts/core`](packages/core) | The interpreter, parser, type system, and standard library. Zero platform dependencies. |
271+
| [`@metta-ts/hyperon`](packages/hyperon) | A TypeScript class API over the core, modeled on Python's `hyperon`. |
272+
| [`@metta-ts/edsl`](packages/edsl) | An ergonomic, typed eDSL: term builders, special-form combinators, and a tagged template. |
273+
| [`@metta-ts/node`](packages/node) | The `metta-ts` CLI, file `import!`, and a `SharedArrayBuffer` worker-thread parallel matcher. |
274+
| [`@metta-ts/browser`](packages/browser) | Browser entry point with an in-memory virtual file system for `import!`. |
275+
| [`@metta-ts/py`](packages/py) | Optional Python interop: PeTTa's `py-call` and Hyperon's `py-atom`, over pythonia or Pyodide. |
276+
| [`@metta-ts/prolog`](packages/prolog) | Optional Prolog interop: PeTTa-compatible predicate calls over SWI-Prolog or SWI-WASM. |
277+
| [`@metta-ts/das-client`](packages/das-client) | Optional client to SingularityNET's Distributed AtomSpace via a Connect gateway. |
214278

215279
## Performance
216280

217-
Pure TypeScript throughout, no escape to native code. The interpreter uses a precomputed-ground short-circuit, structural sharing in substitution, a cons-list instruction stack, and Prolog-style clause indexing (by head functor and by every ground-leaf argument position). A functor-and-argument-keyed query over a 1,000,000-atom knowledge base resolves in about 0.2 to 1.4 ms. See [`packages/node/bench/RESULTS.md`](packages/node/bench/RESULTS.md) for the full benchmark log.
281+
The pure-MeTTa path stays TypeScript throughout, with no escape to native code. The interpreter uses a precomputed-ground short-circuit, structural sharing in substitution, a cons-list instruction stack, and Prolog-style clause indexing (by head functor and by every ground-leaf argument position). A functor-and-argument-keyed query over a 1,000,000-atom knowledge base resolves in about 0.2 to 1.4 ms. See [`packages/node/bench/RESULTS.md`](packages/node/bench/RESULTS.md) for the full benchmark log.
218282

219283
### Head-to-head with PeTTa
220284

@@ -261,6 +325,7 @@ The last holdouts fell in order. `permutations` is a 28-relation conjunctive `(l
261325

262326
- **Semantics:** [hyperon-experimental](https://github.com/trueagi-io/hyperon-experimental), pinned to commit `3f76dc4`.
263327
- **Verified spec and differential oracle:** [LeaTTa](https://github.com/MesTTo/LeaTTa) (Lean 4).
328+
- **Host interop surfaces:** PeTTa-compatible Python and Prolog call forms where they do not depend on PeTTa's evaluator.
264329
- **Distributed AtomSpace:** optional client to SingularityNET DAS via a Connect gateway (Node), reachable from the browser.
265330

266331
## License

0 commit comments

Comments
 (0)