Exact what-if over a live reactive model.

pimas is a small reactive model runtime I built from scratch, published on npm as pimas-ui. You put derived state in signals, memos and a store. speculate answers “what would total be if I set qty to 10?” by recomputing those memos against a shadow of the graph: effects do not run, the live model does not change, and the number you get is the number a real commit would produce. An agent or a React preview UI can use it. Zero runtime dependencies; React is an optional peer.

pimas no longer includes a renderer or JSX: the current release (0.4) is the model runtime only. The renderer lives on in pimas-ui@0.1.2, which is what this site is built with.

Drive the model or watch an agent, then look at the dependency graph below it: the nodes are this model’s own signals and memos, and one lights only when its compute function actually re-ran.

Live demo - drive it, or watch an agent

You are the agent. Pick a pillar, drag its weight, and watch the predicted ranking move through a real speculate - while the committed model on the left does not. Commit to apply it for real.

weight of
1.0×
live model · committed
#1Sweden212
#2Germany206
#3France197
#4Spain190
predicted · speculate, nothing committed
#1Sweden212
#2Germany206
#3France197
#4Spain190
dependency graph · this model
innovationw 1.0governancew 1.0sustainabilityw 1.0scoresruns 1rankingruns 1maxScoreruns 1leaderruns 1franceRankruns 1

This is the dependency graph for this one demo model, hand-wired to match it (not auto-discovered); a node lights laurel only when its compute function genuinely re-ran on the last commit (the count is that node’s real recompute total), and lights ocean, dashed when the current speculate touched it in a shadow with nothing committed.

descriptor() · machine-readable model of this page
ranking : array · Countries ordered by composite score, best first.
leader : string · The country currently ranked #1.
franceRank : number · France's current rank (the goal is a rank of 2 or better).
setWeight(pillar, weight) · Set one pillar's weight in the composite; the ranking recomputes.
subscribe() · live delta stream
commit a change to see deltas pushed here

The predicted panel is bridge.speculatePlan run in a copy-on-write shadow in your browser; the live panel is the committed graph, untouched until you commit. Commit calls commitPlan; the explain() trace and the subscribe() stream above are the real bridge output, not a recording.

How it works.

Reading a value inside a computation subscribes that computation to it, and writing the value re-runs exactly the computations that read it. A signal is a unit of state, a memo is a value derived by a pure function, and an effect acts on the outside world. Updates are glitch-free: a diamond (two paths from one source to one sink) recomputes the sink once, and a value written back equal to what it was stops the cascade.

speculate works because the graph separates the topology (what derives from what) from the values flowing through it. A what-if writes into a shadow overlay and recomputes memos against it, detached and cached, so the real nodes are never touched and no effect fires. Rollback is free: the overlay is dropped. speculatePlan applies several changes in one shadow, so A-then-B is not two previews that reset, and commitPlan applies an approved plan for real. Store edits are shadowed too.

The agent bridge.

pimas-ui/agent turns a model into a surface an agent can use. You declare what is readable with expose(name, fn) and what is callable with action(name, fn). The bridge carries snapshot, subscribe, call, explain, history, speculate, speculatePlan and commitPlan.

  • 1Subscribe. Exposed values push a delta when they change, so the agent does not poll or scrape the DOM.
  • 2Explain. explain() returns a causal record of what an action wrote and which exposed values changed as a result.
  • 3Simulate. speculate returns the predicted state without committing.

toWebMCP, also from pimas-ui/agent, projects the bridge onto WebMCP as the actions plus get_* and simulate_* tools, and installPageAgent puts the same surface on window.__pimas where WebMCP is not available. A preview UI and an agent call the same function, so they cannot disagree about the answer.

Where it fits.

  • →Quantitative models - pricing, project economics, risk, physical models. The math is already pure, so exact what-if is cheap. The demo above runs an OECD-style composite indicator, and the von-neumann lunar-factory model is the other target.
  • →Preview before commit - show the exact resulting state, then commit only what the user or agent approved.
  • →Tooling for AI agents - give an agent a non-committal preview of an action before it fires, as a simulate_* tool.

Limit. speculate is exact only if memos are pure. That is assumed, not enforced: keep I/O in actions and math in memos.

The code is on GitHub and published to npm as pimas-ui. Pre-1.0: pin exact versions.

github.com/noahhyden/pimas →