@metta-ts/debug 1.5.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -26
- package/dist/index.js +1 -48
- package/package.json +6 -13
- package/README.md +0 -25
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { TraceEvent } from '@metta-ts/core';
|
|
3
|
-
|
|
4
|
-
interface TraceSummary {
|
|
5
|
-
readonly grounded: Record<string, number>;
|
|
6
|
-
readonly specialized: string[];
|
|
7
|
-
readonly overflow: string[];
|
|
8
|
-
readonly reductions: number;
|
|
9
|
-
}
|
|
10
|
-
type TraceRunner = (program: string, fuel: number | undefined, imports: Map<string, Atom[]>, opts?: RunOptions) => QueryResult[];
|
|
11
|
-
interface DebugRunOptions {
|
|
12
|
-
readonly fuel?: number | undefined;
|
|
13
|
-
readonly imports?: Map<string, Atom[]> | undefined;
|
|
14
|
-
readonly runOptions?: Omit<RunOptions, "trace"> | undefined;
|
|
15
|
-
}
|
|
16
|
-
interface CallExplanation {
|
|
17
|
-
readonly result: string[];
|
|
18
|
-
readonly trace: TraceEvent[];
|
|
19
|
-
readonly summary: TraceSummary;
|
|
20
|
-
}
|
|
21
|
-
declare function summarize(events: readonly TraceEvent[]): TraceSummary;
|
|
22
|
-
declare function assembleQuery(source: string, call: string): string;
|
|
23
|
-
declare function collectTrace(runner: TraceRunner, program: string, opts?: DebugRunOptions): TraceEvent[];
|
|
24
|
-
declare function explainCall(runner: TraceRunner, source: string, call: string, opts?: DebugRunOptions): CallExplanation;
|
|
25
|
-
|
|
26
|
-
export { type CallExplanation, type DebugRunOptions, type TraceRunner, type TraceSummary, assembleQuery, collectTrace, explainCall, summarize };
|
|
1
|
+
export * from '@mettascript/debug';
|
package/dist/index.js
CHANGED
|
@@ -1,49 +1,2 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
|
|
3
|
-
format
|
|
4
|
-
} from "@metta-ts/core";
|
|
5
|
-
function summarize(events) {
|
|
6
|
-
const grounded = {};
|
|
7
|
-
const specialized = /* @__PURE__ */ new Set();
|
|
8
|
-
const overflow = [];
|
|
9
|
-
let reductions = 0;
|
|
10
|
-
for (const e of events) {
|
|
11
|
-
if (e.kind === "grounded") grounded[e.op] = (grounded[e.op] ?? 0) + 1;
|
|
12
|
-
else if (e.kind === "specialize") specialized.add(`${e.from} -> ${e.to}`);
|
|
13
|
-
else if (e.kind === "overflow") overflow.push(e.atom);
|
|
14
|
-
else reductions++;
|
|
15
|
-
}
|
|
16
|
-
return { grounded, specialized: [...specialized], overflow, reductions };
|
|
17
|
-
}
|
|
18
|
-
function assembleQuery(source, call) {
|
|
19
|
-
const trimmed = call.trim();
|
|
20
|
-
const q = trimmed.startsWith("!") ? trimmed : `!${trimmed}`;
|
|
21
|
-
return `${source}
|
|
22
|
-
${q}`;
|
|
23
|
-
}
|
|
24
|
-
function runWithTrace(runner, program, opts = {}) {
|
|
25
|
-
const trace = [];
|
|
26
|
-
const runOptions = {
|
|
27
|
-
...opts.runOptions ?? {},
|
|
28
|
-
trace: (e) => trace.push(e)
|
|
29
|
-
};
|
|
30
|
-
const groups = runner(program, opts.fuel, opts.imports ?? /* @__PURE__ */ new Map(), runOptions);
|
|
31
|
-
return { groups, trace };
|
|
32
|
-
}
|
|
33
|
-
function collectTrace(runner, program, opts) {
|
|
34
|
-
return runWithTrace(runner, program, opts).trace;
|
|
35
|
-
}
|
|
36
|
-
function explainCall(runner, source, call, opts) {
|
|
37
|
-
const { groups, trace } = runWithTrace(runner, assembleQuery(source, call), opts);
|
|
38
|
-
return {
|
|
39
|
-
result: groups.at(-1)?.results.map(format) ?? [],
|
|
40
|
-
trace,
|
|
41
|
-
summary: summarize(trace)
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export {
|
|
45
|
-
assembleQuery,
|
|
46
|
-
collectTrace,
|
|
47
|
-
explainCall,
|
|
48
|
-
summarize
|
|
49
|
-
};
|
|
2
|
+
export * from "@mettascript/debug";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metta-ts/debug",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@
|
|
19
|
+
"@mettascript/debug": "2.0.0"
|
|
20
20
|
},
|
|
21
21
|
"author": "MesTTo",
|
|
22
22
|
"engines": {
|
|
@@ -27,22 +27,15 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"description": "
|
|
31
|
-
"keywords": [
|
|
32
|
-
"metta",
|
|
33
|
-
"hyperon",
|
|
34
|
-
"debug",
|
|
35
|
-
"trace",
|
|
36
|
-
"typescript"
|
|
37
|
-
],
|
|
30
|
+
"description": "Compatibility shim for @mettascript/debug.",
|
|
38
31
|
"repository": {
|
|
39
32
|
"type": "git",
|
|
40
|
-
"url": "git+https://github.com/MesTTo/
|
|
33
|
+
"url": "git+https://github.com/MesTTo/MeTTaScript.git",
|
|
41
34
|
"directory": "packages/debug"
|
|
42
35
|
},
|
|
43
|
-
"homepage": "https://github.com/MesTTo/
|
|
36
|
+
"homepage": "https://github.com/MesTTo/MeTTaScript#readme",
|
|
44
37
|
"bugs": {
|
|
45
|
-
"url": "https://github.com/MesTTo/
|
|
38
|
+
"url": "https://github.com/MesTTo/MeTTaScript/issues"
|
|
46
39
|
},
|
|
47
40
|
"scripts": {
|
|
48
41
|
"build": "tsup src/index.ts --format esm --dts --clean"
|
package/README.md
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
SPDX-FileCopyrightText: 2026 MesTTo
|
|
3
|
-
SPDX-License-Identifier: MIT
|
|
4
|
-
-->
|
|
5
|
-
|
|
6
|
-
# @metta-ts/debug
|
|
7
|
-
|
|
8
|
-
`@metta-ts/debug` contains the host-free debugger engine used by `metta-debug`
|
|
9
|
-
and embedders such as language servers.
|
|
10
|
-
|
|
11
|
-
The package does not read files, register global output sinks, or import Node
|
|
12
|
-
APIs. Callers provide the exact runner they already use.
|
|
13
|
-
|
|
14
|
-
```ts
|
|
15
|
-
import { explainCall } from "@metta-ts/debug";
|
|
16
|
-
import { runProgram } from "@metta-ts/core";
|
|
17
|
-
|
|
18
|
-
const report = explainCall(runProgram, "(= (double $x) (* $x 2))", "(double 21)");
|
|
19
|
-
|
|
20
|
-
console.log(report.result); // ["42"]
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Use `collectTrace` when the caller already has an assembled program and only
|
|
24
|
-
needs the raw trace event stream. Use `summarize` when the caller already
|
|
25
|
-
collected events and needs the grouped `metta-debug why` counters.
|