dagql
Programs are data. Once you build an MVFM program, DagQL lets you inspect, rewrite, and transform the AST before running it.
selectWhere(nexpr, predicate)finds nodes in the graph.replaceWhere(nexpr, predicate, newKind)swaps node kinds.pipe(nexpr, f1, f2, ...)chains transformations.commit(dirtyExpr)seals the result for execution.
The pattern becomes: app → prog → dagql → fold.
const app = mvfm(prelude, console_);
// build a program: (x + 10) * 2, then log it
const prog = app({ x: "number" }, ($) => {
const sum = $.add($.input.x, 10);
return $.begin(
$.console.log("result:", $.mul(sum, 2)),
$.mul(sum, 2)
);
});
const injected = injectInput(prog, { x: 5 });
// rewrite: swap add → mul, so it becomes (x * 10) * 2
const rewritten = commit(
replaceWhere(injected.__nexpr, byKind("num/add"), "num/mul")
);
await fold(rewritten, defaults(app)); Ctrl+Enter