@mojir/dvala 0.0.12 → 0.0.13
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/cli/cli.js +58 -19
- package/package.json +2 -5
package/dist/cli/cli.js
CHANGED
|
@@ -466,7 +466,7 @@ function findAllOccurrences(input, pattern) {
|
|
|
466
466
|
}
|
|
467
467
|
//#endregion
|
|
468
468
|
//#region package.json
|
|
469
|
-
var version = "0.0.
|
|
469
|
+
var version = "0.0.13";
|
|
470
470
|
//#endregion
|
|
471
471
|
//#region src/typeGuards/string.ts
|
|
472
472
|
function isString(value, options = {}) {
|
|
@@ -27788,6 +27788,7 @@ function minifyTokenStream(tokenStream, { removeWhiteSpace }) {
|
|
|
27788
27788
|
}
|
|
27789
27789
|
//#endregion
|
|
27790
27790
|
//#region src/evaluator/effectTypes.ts
|
|
27791
|
+
const SUSPENDED_MESSAGE = "Program suspended";
|
|
27791
27792
|
/**
|
|
27792
27793
|
* Generate a UUID for identifying a run() or resume() call.
|
|
27793
27794
|
* Uses crypto.randomUUID() when available, falls back to a simple generator.
|
|
@@ -27821,9 +27822,9 @@ function effectNameMatchesPattern(effectName, pattern) {
|
|
|
27821
27822
|
* Returns an array of `[pattern, handler]` pairs.
|
|
27822
27823
|
*/
|
|
27823
27824
|
function findMatchingHandlers(effectName, handlers) {
|
|
27824
|
-
if (!handlers) return [];
|
|
27825
|
+
if (!handlers || handlers.length === 0) return [];
|
|
27825
27826
|
const result = [];
|
|
27826
|
-
for (const
|
|
27827
|
+
for (const { pattern, handler } of handlers) if (effectNameMatchesPattern(effectName, pattern)) result.push([pattern, handler]);
|
|
27827
27828
|
return result;
|
|
27828
27829
|
}
|
|
27829
27830
|
/**
|
|
@@ -29543,6 +29544,7 @@ function applyFrame(frame, value, k) {
|
|
|
29543
29544
|
k
|
|
29544
29545
|
};
|
|
29545
29546
|
}
|
|
29547
|
+
case "AutoCheckpoint": return applyAutoCheckpoint(frame, k);
|
|
29546
29548
|
default: throw new DvalaError(`Unhandled frame type: ${frame.type}`, void 0);
|
|
29547
29549
|
}
|
|
29548
29550
|
}
|
|
@@ -30347,6 +30349,27 @@ function dispatchPerform(effect, args, k, sourceCodeInfo, handlers, signal, snap
|
|
|
30347
30349
|
snapshotState.snapshots.push(snapshot);
|
|
30348
30350
|
if (snapshotState.maxSnapshots !== void 0 && snapshotState.snapshots.length > snapshotState.maxSnapshots) snapshotState.snapshots.shift();
|
|
30349
30351
|
}
|
|
30352
|
+
if (snapshotState?.autoCheckpoint && effect.name !== "dvala.checkpoint") {
|
|
30353
|
+
const topFrame = k[0];
|
|
30354
|
+
if (topFrame?.type === "AutoCheckpoint" && topFrame.phase === "awaitEffect") k = k.slice(1);
|
|
30355
|
+
else {
|
|
30356
|
+
const autoCheckpointFrame = {
|
|
30357
|
+
type: "AutoCheckpoint",
|
|
30358
|
+
phase: "awaitCheckpoint",
|
|
30359
|
+
effect,
|
|
30360
|
+
args,
|
|
30361
|
+
sourceCodeInfo
|
|
30362
|
+
};
|
|
30363
|
+
const checkpointMessage = `Auto checkpoint before ${effect.name}`;
|
|
30364
|
+
return {
|
|
30365
|
+
type: "Perform",
|
|
30366
|
+
effect: getEffectRef("dvala.checkpoint"),
|
|
30367
|
+
args: [checkpointMessage],
|
|
30368
|
+
k: [autoCheckpointFrame, ...k],
|
|
30369
|
+
sourceCodeInfo
|
|
30370
|
+
};
|
|
30371
|
+
}
|
|
30372
|
+
}
|
|
30350
30373
|
for (let i = 0; i < k.length; i++) {
|
|
30351
30374
|
const frame = k[i];
|
|
30352
30375
|
if (frame.type === "TryWith") {
|
|
@@ -30873,6 +30896,22 @@ function applyDebugStep(frame, value, k) {
|
|
|
30873
30896
|
k
|
|
30874
30897
|
};
|
|
30875
30898
|
}
|
|
30899
|
+
function applyAutoCheckpoint(frame, k) {
|
|
30900
|
+
const markerFrame = {
|
|
30901
|
+
type: "AutoCheckpoint",
|
|
30902
|
+
phase: "awaitEffect",
|
|
30903
|
+
effect: frame.effect,
|
|
30904
|
+
args: frame.args,
|
|
30905
|
+
sourceCodeInfo: frame.sourceCodeInfo
|
|
30906
|
+
};
|
|
30907
|
+
return {
|
|
30908
|
+
type: "Perform",
|
|
30909
|
+
effect: frame.effect,
|
|
30910
|
+
args: frame.args,
|
|
30911
|
+
k: [markerFrame, ...k],
|
|
30912
|
+
sourceCodeInfo: frame.sourceCodeInfo
|
|
30913
|
+
};
|
|
30914
|
+
}
|
|
30876
30915
|
/**
|
|
30877
30916
|
* Wrap a MaybePromise<Any> result into a Step or Promise<Step>.
|
|
30878
30917
|
* If the result is a value, return a ValueStep immediately.
|
|
@@ -31054,9 +31093,9 @@ function evaluateNode(node, contextStack) {
|
|
|
31054
31093
|
* is passed to every host handler. Used for `race()` cancellation (Phase 6)
|
|
31055
31094
|
* and host-side timeouts.
|
|
31056
31095
|
*/
|
|
31057
|
-
async function evaluateWithEffects(ast, contextStack, handlers, maxSnapshots, deserializeOptions) {
|
|
31096
|
+
async function evaluateWithEffects(ast, contextStack, handlers, maxSnapshots, deserializeOptions, autoCheckpoint) {
|
|
31058
31097
|
const signal = new AbortController().signal;
|
|
31059
|
-
return runEffectLoop(buildInitialStep(ast.body, contextStack), handlers, signal, void 0, maxSnapshots, deserializeOptions);
|
|
31098
|
+
return runEffectLoop(buildInitialStep(ast.body, contextStack), handlers, signal, void 0, maxSnapshots, deserializeOptions, autoCheckpoint);
|
|
31060
31099
|
}
|
|
31061
31100
|
/**
|
|
31062
31101
|
* Evaluate an AST synchronously with effect handler support.
|
|
@@ -31086,13 +31125,14 @@ function evaluateWithSyncEffects(ast, contextStack, effectHandlers) {
|
|
|
31086
31125
|
* to fire a `perform(dvala.debug.step, stepInfo)` after evaluation,
|
|
31087
31126
|
* enabling the time-travel debugger.
|
|
31088
31127
|
*/
|
|
31089
|
-
async function runEffectLoop(initial, handlers, signal, initialSnapshotState, maxSnapshots, deserializeOptions) {
|
|
31090
|
-
const debugMode = handlers
|
|
31128
|
+
async function runEffectLoop(initial, handlers, signal, initialSnapshotState, maxSnapshots, deserializeOptions, autoCheckpoint) {
|
|
31129
|
+
const debugMode = Array.isArray(handlers) && handlers.some((h) => h.pattern === "dvala.debug.step");
|
|
31091
31130
|
const snapshotState = {
|
|
31092
31131
|
snapshots: initialSnapshotState ? initialSnapshotState.snapshots : [],
|
|
31093
31132
|
nextSnapshotIndex: initialSnapshotState ? initialSnapshotState.nextSnapshotIndex : 0,
|
|
31094
31133
|
runId: generateRunId(),
|
|
31095
|
-
...maxSnapshots !== void 0 ? { maxSnapshots } : {}
|
|
31134
|
+
...maxSnapshots !== void 0 ? { maxSnapshots } : {},
|
|
31135
|
+
...autoCheckpoint ? { autoCheckpoint } : {}
|
|
31096
31136
|
};
|
|
31097
31137
|
let step = initial;
|
|
31098
31138
|
for (;;) try {
|
|
@@ -31138,7 +31178,7 @@ async function runEffectLoop(initial, handlers, signal, initialSnapshotState, ma
|
|
|
31138
31178
|
timestamp: Date.now(),
|
|
31139
31179
|
index: snapshotState.nextSnapshotIndex++,
|
|
31140
31180
|
runId: snapshotState.runId,
|
|
31141
|
-
message:
|
|
31181
|
+
message: SUSPENDED_MESSAGE,
|
|
31142
31182
|
meta: error.meta,
|
|
31143
31183
|
effectName: error.effectName,
|
|
31144
31184
|
effectArgs: error.effectArgs
|
|
@@ -31314,15 +31354,11 @@ function createDvala(options) {
|
|
|
31314
31354
|
}
|
|
31315
31355
|
function mergeEffectHandlers(runEffectHandlers) {
|
|
31316
31356
|
if (!factoryEffectHandlers && !runEffectHandlers) return void 0;
|
|
31317
|
-
|
|
31318
|
-
if (factoryEffectHandlers) {
|
|
31319
|
-
for (const [k, v] of Object.entries(factoryEffectHandlers)) if (!(k in result)) result[k] = v;
|
|
31320
|
-
}
|
|
31321
|
-
return result;
|
|
31357
|
+
return [...runEffectHandlers ?? [], ...factoryEffectHandlers ?? []];
|
|
31322
31358
|
}
|
|
31323
31359
|
function assertNotPureWithHandlers(pure, effectHandlers) {
|
|
31324
31360
|
if (!pure) return;
|
|
31325
|
-
if (effectHandlers &&
|
|
31361
|
+
if (effectHandlers && effectHandlers.length > 0) throw new TypeError("Cannot use pure mode with effect handlers");
|
|
31326
31362
|
}
|
|
31327
31363
|
return {
|
|
31328
31364
|
run(source, runOptions) {
|
|
@@ -31373,7 +31409,7 @@ function createDvala(options) {
|
|
|
31373
31409
|
const result = await evaluateWithEffects(buildAst(isDvalaBundle(source) ? source.program : source), contextStack, effectHandlers, runOptions?.maxSnapshots, {
|
|
31374
31410
|
values: bindings,
|
|
31375
31411
|
modules
|
|
31376
|
-
});
|
|
31412
|
+
}, runOptions?.autoCheckpoint);
|
|
31377
31413
|
if (result.type === "completed") return {
|
|
31378
31414
|
...result,
|
|
31379
31415
|
definedBindings: contextStack.getModuleScopeBindings()
|
|
@@ -33878,9 +33914,12 @@ async function execute(expression, bindings, readLine) {
|
|
|
33878
33914
|
try {
|
|
33879
33915
|
const runResult = await _dvala.runAsync(expression, {
|
|
33880
33916
|
bindings,
|
|
33881
|
-
effectHandlers: {
|
|
33882
|
-
|
|
33883
|
-
|
|
33917
|
+
effectHandlers: [{
|
|
33918
|
+
pattern: "dvala.io.read-line",
|
|
33919
|
+
handler: async ({ args, resume }) => {
|
|
33920
|
+
resume(await readLine(typeof args[0] === "string" ? args[0] : ""));
|
|
33921
|
+
}
|
|
33922
|
+
}]
|
|
33884
33923
|
});
|
|
33885
33924
|
if (runResult.type === "error") throw runResult.error;
|
|
33886
33925
|
const result = runResult.type === "completed" ? runResult.value : null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mojir/dvala",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "dvala",
|
|
5
5
|
"author": "Albert Mojir",
|
|
6
6
|
"license": "MIT",
|
|
@@ -137,7 +137,6 @@
|
|
|
137
137
|
"build-vscode-ext": "wireit",
|
|
138
138
|
"dvala": "node ./dist/cli/cli.js",
|
|
139
139
|
"dev": "npx serve docs -p 9901",
|
|
140
|
-
"release": "npm version",
|
|
141
140
|
"test:e2e": "npx playwright test",
|
|
142
141
|
"lcov": "open-cli ./coverage/index.html",
|
|
143
142
|
"mcp:inspect": "npx @modelcontextprotocol/inspector node ./dist/mcp-server/server.js"
|
|
@@ -305,9 +304,7 @@
|
|
|
305
304
|
"output": [
|
|
306
305
|
"playground-builder/build/**",
|
|
307
306
|
"playground-www/build/**",
|
|
308
|
-
"docs
|
|
309
|
-
"docs/index.html",
|
|
310
|
-
"docs/styles.css"
|
|
307
|
+
"docs/**"
|
|
311
308
|
],
|
|
312
309
|
"clean": "if-file-deleted"
|
|
313
310
|
},
|