@earnestjs/model 0.0.0-stage → 0.2.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/replay.js ADDED
@@ -0,0 +1,99 @@
1
+ import { attempt, namer, nextState, startsOf } from "./search.js";
2
+ import { keyOf, toJson } from "./values.js";
3
+ const messageOf = (thrown) => thrown instanceof Error ? thrown.message : String(thrown);
4
+ const readAll = (where, declared, named) => {
5
+ const given = new Map(named.map((each) => [each.name, each.value]));
6
+ const stray = named.find((each) => !declared.some(([name]) => name === each.name));
7
+ if (stray !== undefined) {
8
+ throw new Error(`${where} names \`${stray.name}\`, which is not declared`);
9
+ }
10
+ return Object.fromEntries(declared.map(([name, declaration]) => {
11
+ const json = given.get(name);
12
+ if (json === undefined) {
13
+ throw new Error(`${where} has no value for \`${name}\``);
14
+ }
15
+ try {
16
+ return [name, declaration.fromJson(json)];
17
+ }
18
+ catch (thrown) {
19
+ throw new Error(`${where} can't be read at \`${name}\`: ${messageOf(thrown)}`);
20
+ }
21
+ }));
22
+ };
23
+ const outside = (declared, row) => {
24
+ const found = declared.find(([name, declaration]) => !declaration.has(row[name]));
25
+ return found === undefined ? null : found[0];
26
+ };
27
+ const stateKey = (fields, row) => fields.map(([name]) => keyOf(row[name])).join(";");
28
+ const text = (value) => JSON.stringify(toJson(value));
29
+ const actionFor = (where, actions, step, options) => {
30
+ const name = namer(options.exports);
31
+ const byId = actions.filter((each) => name(each.part, each.sentence) === step.action);
32
+ const matching = byId.length > 0 ? byId : actions.filter((each) => each.sentence === step.label);
33
+ const [found, ...others] = matching;
34
+ if (found === undefined) {
35
+ throw new Error(`${where}: the model has no action with this id or label; pass the model file's exports so that ids can be matched`);
36
+ }
37
+ if (others.length > 0) {
38
+ throw new Error(`${where}: more than one action matches; pass the model file's exports so that ids can be matched`);
39
+ }
40
+ return found;
41
+ };
42
+ const applied = (where, fields, action, state, input) => {
43
+ const unfit = outside(fields, state);
44
+ if (unfit !== null) {
45
+ throw new Error(`${where}: the state before it is out of range at \`${unfit}\`, so no action can follow`);
46
+ }
47
+ const strange = outside(action.inputs, input);
48
+ if (strange !== null) {
49
+ throw new Error(`${where}: the input \`${strange}\` is ${text(input[strange])}, which is not a value it declares`);
50
+ }
51
+ const can = attempt(() => action.when(state, input));
52
+ if (can.fault !== null) {
53
+ throw new Error(`${where}: the condition of the action ${can.fault} in this state`);
54
+ }
55
+ if (!can.value) {
56
+ throw new Error(`${where}: the condition of the action is false in this state`);
57
+ }
58
+ const next = nextState(action, state, input);
59
+ if (next.fault !== null) {
60
+ throw new Error(`${where}: the change of the action ${next.fault} in this state`);
61
+ }
62
+ return next.value;
63
+ };
64
+ /**
65
+ * Applies a path one action at a time and gives every state it passes through, the start state
66
+ * first, each with its fields in JSON form. Throws an error that names the step when the path
67
+ * does not begin at a start state of the model, or of `options.setup` when it is given, a step names no action of the model, an input is missing or
68
+ * undeclared, the action's `when` is false, the action can't be evaluated, or the state after
69
+ * the action differs from the step's `state`. Set members may be listed in any order.
70
+ */
71
+ export const replay = (model, path, options = {}) => {
72
+ const fields = Object.entries(model.fields);
73
+ const actions = model.runners().actions;
74
+ const given = readAll(`${model.name}: the start of the path`, fields, path.start);
75
+ const starts = startsOf(model, options.setup, "replay");
76
+ const start = starts.find((each) => stateKey(fields, each) === stateKey(fields, given));
77
+ if (start === undefined) {
78
+ const whose = options.setup === undefined ? "the model" : "the setup";
79
+ throw new Error(`${model.name}: the path does not begin at a start state of ${whose}`);
80
+ }
81
+ const states = [start];
82
+ let state = start;
83
+ for (const [position, step] of path.steps.entries()) {
84
+ const where = `${model.name}: step ${position + 1} (${step.action})`;
85
+ const action = actionFor(where, actions, step, options);
86
+ const input = readAll(`${where}: the input`, action.inputs, step.input ?? []);
87
+ const next = applied(where, fields, action, state, input);
88
+ const expected = readAll(`${where}: the state`, fields, step.state);
89
+ const differing = fields
90
+ .filter(([name]) => keyOf(next[name]) !== keyOf(expected[name]))
91
+ .map(([name]) => `\`${name}\` is ${text(next[name])} but the path has ${text(expected[name])}`);
92
+ if (differing.length > 0) {
93
+ throw new Error(`${where}: the state after the action differs from the path: ${differing.join("; ")}`);
94
+ }
95
+ states.push(next);
96
+ state = next;
97
+ }
98
+ return states.map((row) => Object.fromEntries(fields.map(([name]) => [name, toJson(row[name])])));
99
+ };
package/dist/runs.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ /** One way a state changes into another: the positions of both states and of the action. */
2
+ export interface Edge {
3
+ readonly from: number;
4
+ readonly to: number;
5
+ readonly action: number;
6
+ }
7
+ /**
8
+ * The states a search visited and the actions between them, for judging a rule about runs.
9
+ * `edges` leaves out an action that keeps the state as it is, lists each edge once and is sorted
10
+ * by `from`, then `to`, then `action`. `fair` holds the positions of the actions that are not put
11
+ * off forever. `parents` gives the state each state was first reached from, or `null` for a start
12
+ * state, and `depth` the number of steps of that shortest way.
13
+ */
14
+ export interface Graph {
15
+ readonly states: number;
16
+ readonly edges: readonly Edge[];
17
+ readonly fair: readonly number[];
18
+ readonly parents: readonly (number | null)[];
19
+ readonly depth: readonly number[];
20
+ }
21
+ /**
22
+ * A run that never reaches the state a rule wants: `states` from a start state on, with the
23
+ * action taken into each state in `actions` (`null` for the first one that leads there, and for
24
+ * the start state). The steps from `repeatsFrom` on can repeat forever; `null` means the run
25
+ * stays in the last state.
26
+ */
27
+ export interface Lasso {
28
+ readonly states: number[];
29
+ readonly actions: (number | null)[];
30
+ repeatsFrom: number | null;
31
+ }
32
+ /**
33
+ * Gives the function that finds, for one rule about runs, a run of `graph` that never reaches
34
+ * the state the rule wants, or `null` when every run reaches it. `startsHere` says for each
35
+ * state whether the rule starts there, and `reached` whether the state is one the rule wants.
36
+ * A run never stops while an edge leaves its state, and never puts off forever a fair action
37
+ * that stays possible. The run found has the fewest steps before it stays or repeats. `"lost"`
38
+ * means a run exists and its loop could not be walked, which a graph of a finished search never
39
+ * gives.
40
+ */
41
+ export declare const hunter: (graph: Graph) => ((startsHere: readonly boolean[], reached: readonly boolean[]) => Lasso | "lost" | null);
package/dist/runs.js ADDED
@@ -0,0 +1,325 @@
1
+ const NOWHERE = -1;
2
+ class Outgoing {
3
+ #first;
4
+ #edges;
5
+ constructor(states, edges) {
6
+ this.#edges = edges;
7
+ this.#first = Array.from({ length: states + 1 }, () => 0);
8
+ for (const edge of edges) {
9
+ this.#first[edge.from + 1] = (this.#first[edge.from + 1] ?? 0) + 1;
10
+ }
11
+ let total = 0;
12
+ for (const [position, count] of this.#first.entries()) {
13
+ total += count;
14
+ this.#first[position] = total;
15
+ }
16
+ }
17
+ of(from) {
18
+ return this.#edges.slice(this.#first[from] ?? 0, this.#first[from + 1] ?? 0);
19
+ }
20
+ at(from, position) {
21
+ const index = (this.#first[from] ?? 0) + position;
22
+ return index < (this.#first[from + 1] ?? 0) ? this.#edges[index] : undefined;
23
+ }
24
+ firstAction(from, to) {
25
+ return this.of(from).find((edge) => edge.to === to)?.action ?? null;
26
+ }
27
+ }
28
+ const groupsOf = (out, inside) => {
29
+ const states = inside.length;
30
+ const of = Array.from({ length: states }, () => NOWHERE);
31
+ const sizes = [];
32
+ const order = Array.from({ length: states }, () => NOWHERE);
33
+ const low = Array.from({ length: states }, () => NOWHERE);
34
+ const held = [];
35
+ const onHold = Array.from({ length: states }, () => false);
36
+ const walk = [];
37
+ let nextOrder = 0;
38
+ for (let root = 0; root < states; root += 1) {
39
+ if (inside[root] !== true || order[root] !== NOWHERE) {
40
+ continue;
41
+ }
42
+ walk.push([root, 0]);
43
+ for (let top = walk.pop(); top !== undefined; top = walk.pop()) {
44
+ const [state, tried] = top;
45
+ if (tried === 0) {
46
+ order[state] = nextOrder;
47
+ low[state] = nextOrder;
48
+ nextOrder += 1;
49
+ held.push(state);
50
+ onHold[state] = true;
51
+ }
52
+ const edge = out.at(state, tried);
53
+ if (edge !== undefined) {
54
+ walk.push([state, tried + 1]);
55
+ if (inside[edge.to] !== true) {
56
+ continue;
57
+ }
58
+ if (order[edge.to] === NOWHERE) {
59
+ walk.push([edge.to, 0]);
60
+ }
61
+ else if (onHold[edge.to] === true) {
62
+ low[state] = Math.min(low[state] ?? 0, order[edge.to] ?? 0);
63
+ }
64
+ continue;
65
+ }
66
+ if (low[state] === order[state]) {
67
+ const group = sizes.length;
68
+ let size = 0;
69
+ for (let member = held.pop(); member !== undefined; member = held.pop()) {
70
+ onHold[member] = false;
71
+ of[member] = group;
72
+ size += 1;
73
+ if (member === state) {
74
+ break;
75
+ }
76
+ }
77
+ sizes.push(size);
78
+ }
79
+ const parent = walk.at(-1);
80
+ if (parent !== undefined) {
81
+ low[parent[0]] = Math.min(low[parent[0]] ?? 0, low[state] ?? 0);
82
+ }
83
+ }
84
+ }
85
+ return { of, sizes };
86
+ };
87
+ class Hunt {
88
+ #graph;
89
+ #out;
90
+ #possible;
91
+ constructor(graph) {
92
+ this.#graph = graph;
93
+ this.#out = new Outgoing(graph.states, graph.edges);
94
+ this.#possible = graph.fair.map((action) => {
95
+ const flags = Array.from({ length: graph.states }, () => false);
96
+ for (const edge of graph.edges) {
97
+ if (edge.action === action) {
98
+ flags[edge.from] = true;
99
+ }
100
+ }
101
+ return flags;
102
+ });
103
+ }
104
+ #can(number, state) {
105
+ return this.#possible[number]?.[state] === true;
106
+ }
107
+ #doomed(inside, groups) {
108
+ const { fair } = this.#graph;
109
+ const flagsPerGroup = () => fair.map(() => Array.from({ length: groups.sizes.length }, () => false));
110
+ const putOff = flagsPerGroup();
111
+ const taken = flagsPerGroup();
112
+ for (const [state, group] of groups.of.entries()) {
113
+ if (group === NOWHERE) {
114
+ continue;
115
+ }
116
+ for (const [number, action] of fair.entries()) {
117
+ if (!this.#can(number, state)) {
118
+ (putOff[number] ?? [])[group] = true;
119
+ }
120
+ const insideTheGroup = this.#out
121
+ .of(state)
122
+ .some((edge) => edge.action === action && groups.of[edge.to] === group);
123
+ if (insideTheGroup) {
124
+ (taken[number] ?? [])[group] = true;
125
+ }
126
+ }
127
+ }
128
+ return inside.map((_, state) => {
129
+ const group = groups.of[state] ?? NOWHERE;
130
+ if (group === NOWHERE) {
131
+ return false;
132
+ }
133
+ if ((groups.sizes[group] ?? 0) < 2) {
134
+ return this.#out.at(state, 0) === undefined;
135
+ }
136
+ return fair.every((_action, number) => putOff[number]?.[group] === true || taken[number]?.[group] === true);
137
+ });
138
+ }
139
+ #wayIn(inside, triggers, doomed) {
140
+ const { depth } = this.#graph;
141
+ const depthOf = (state) => depth[state] ?? 0;
142
+ const sources = inside
143
+ .map((_, state) => state)
144
+ .filter((state) => triggers[state] === true && inside[state] === true)
145
+ .sort((one, other) => depthOf(one) - depthOf(other) || one - other);
146
+ let nextSource = 0;
147
+ const seen = inside.map(() => false);
148
+ const via = inside.map(() => NOWHERE);
149
+ const injectUpTo = (level, into) => {
150
+ for (let source = sources[nextSource]; source !== undefined && depthOf(source) <= level; source = sources[nextSource]) {
151
+ nextSource += 1;
152
+ if (seen[source] !== true) {
153
+ seen[source] = true;
154
+ into.push(source);
155
+ }
156
+ }
157
+ };
158
+ const first = sources[0];
159
+ if (first === undefined) {
160
+ return null;
161
+ }
162
+ let level = depthOf(first);
163
+ let frontier = [];
164
+ for (;;) {
165
+ injectUpTo(level, frontier);
166
+ frontier.sort((one, other) => one - other);
167
+ const found = frontier.find((state) => doomed[state] === true);
168
+ if (found !== undefined) {
169
+ const chain = [found];
170
+ for (let state = via[found] ?? NOWHERE; state !== NOWHERE; state = via[state] ?? NOWHERE) {
171
+ chain.push(state);
172
+ }
173
+ return chain.reverse();
174
+ }
175
+ const next = [];
176
+ injectUpTo(level + 1, next);
177
+ for (const state of frontier) {
178
+ for (const edge of this.#out.of(state)) {
179
+ if (inside[edge.to] === true && seen[edge.to] !== true) {
180
+ seen[edge.to] = true;
181
+ via[edge.to] = state;
182
+ next.push(edge.to);
183
+ }
184
+ }
185
+ }
186
+ if (next.length === 0) {
187
+ const waiting = sources[nextSource];
188
+ if (waiting === undefined) {
189
+ return null;
190
+ }
191
+ level = depthOf(waiting);
192
+ }
193
+ else {
194
+ level += 1;
195
+ }
196
+ frontier = next;
197
+ }
198
+ }
199
+ #route(from, group, groups, arrived) {
200
+ const via = new Map();
201
+ const queue = [from];
202
+ for (let head = 0; head < queue.length; head += 1) {
203
+ const state = queue[head] ?? from;
204
+ for (const edge of this.#out.of(state)) {
205
+ if (groups.of[edge.to] !== group) {
206
+ continue;
207
+ }
208
+ if (arrived(edge.to)) {
209
+ const chain = [edge.to, state];
210
+ for (let before = state; before !== from;) {
211
+ const earlier = via.get(before);
212
+ if (earlier === undefined) {
213
+ return null;
214
+ }
215
+ before = earlier;
216
+ chain.push(before);
217
+ }
218
+ return chain.reverse();
219
+ }
220
+ if (edge.to !== from && !via.has(edge.to)) {
221
+ via.set(edge.to, state);
222
+ queue.push(edge.to);
223
+ }
224
+ }
225
+ }
226
+ return null;
227
+ }
228
+ #extend(lasso, chain) {
229
+ for (const [position, to] of chain.entries()) {
230
+ const from = chain[position - 1];
231
+ if (from !== undefined) {
232
+ lasso.states.push(to);
233
+ lasso.actions.push(this.#out.firstAction(from, to));
234
+ }
235
+ }
236
+ }
237
+ #turn(lasso, groups) {
238
+ const home = lasso.states.at(-1);
239
+ if (home === undefined) {
240
+ return false;
241
+ }
242
+ const group = groups.of[home] ?? NOWHERE;
243
+ const begin = lasso.states.length - 1;
244
+ for (const [number, action] of this.#graph.fair.entries()) {
245
+ const here = lasso.states.at(-1) ?? home;
246
+ const waited = lasso.states.slice(begin).some((state) => !this.#can(number, state));
247
+ const happened = lasso.actions.slice(begin + 1).includes(action);
248
+ if (waited || happened) {
249
+ continue;
250
+ }
251
+ const waitsSomewhere = groups.of.some((found, state) => found === group && !this.#can(number, state));
252
+ if (waitsSomewhere) {
253
+ const chain = this.#route(here, group, groups, (state) => !this.#can(number, state));
254
+ if (chain === null) {
255
+ return false;
256
+ }
257
+ this.#extend(lasso, chain);
258
+ continue;
259
+ }
260
+ const takes = (state) => this.#out.of(state).find((edge) => edge.action === action && groups.of[edge.to] === group);
261
+ if (takes(here) === undefined) {
262
+ const chain = this.#route(here, group, groups, (state) => takes(state) !== undefined);
263
+ if (chain === null) {
264
+ return false;
265
+ }
266
+ this.#extend(lasso, chain);
267
+ }
268
+ const edge = takes(lasso.states.at(-1) ?? home);
269
+ if (edge === undefined) {
270
+ return false;
271
+ }
272
+ lasso.states.push(edge.to);
273
+ lasso.actions.push(edge.action);
274
+ }
275
+ const here = lasso.states.at(-1) ?? home;
276
+ if (here !== home || lasso.states.length - 1 === begin) {
277
+ const chain = this.#route(here, group, groups, (state) => state === home);
278
+ if (chain === null) {
279
+ return false;
280
+ }
281
+ this.#extend(lasso, chain);
282
+ }
283
+ lasso.repeatsFrom = begin;
284
+ return true;
285
+ }
286
+ lasso(startsHere, reached) {
287
+ const inside = reached.map((reachedHere) => !reachedHere);
288
+ const groups = groupsOf(this.#out, inside);
289
+ const doomed = this.#doomed(inside, groups);
290
+ const chain = this.#wayIn(inside, startsHere, doomed);
291
+ const entered = chain?.[0];
292
+ if (chain === null || entered === undefined) {
293
+ return null;
294
+ }
295
+ const before = [entered];
296
+ for (let parent = this.#graph.parents[entered] ?? null; parent !== null; parent = this.#graph.parents[parent] ?? null) {
297
+ before.push(parent);
298
+ }
299
+ before.reverse();
300
+ const lasso = {
301
+ states: before,
302
+ actions: before.map(() => null),
303
+ repeatsFrom: null,
304
+ };
305
+ this.#extend(lasso, chain);
306
+ const last = lasso.states.at(-1) ?? entered;
307
+ if ((groups.sizes[groups.of[last] ?? NOWHERE] ?? 0) >= 2 && !this.#turn(lasso, groups)) {
308
+ return "lost";
309
+ }
310
+ return lasso;
311
+ }
312
+ }
313
+ /**
314
+ * Gives the function that finds, for one rule about runs, a run of `graph` that never reaches
315
+ * the state the rule wants, or `null` when every run reaches it. `startsHere` says for each
316
+ * state whether the rule starts there, and `reached` whether the state is one the rule wants.
317
+ * A run never stops while an edge leaves its state, and never puts off forever a fair action
318
+ * that stays possible. The run found has the fewest steps before it stays or repeats. `"lost"`
319
+ * means a run exists and its loop could not be walked, which a graph of a finished search never
320
+ * gives.
321
+ */
322
+ export const hunter = (graph) => {
323
+ const hunt = new Hunt(graph);
324
+ return (startsHere, reached) => hunt.lasso(startsHere, reached);
325
+ };
@@ -0,0 +1,130 @@
1
+ import { type Status, type Verdict } from "./breadth.ts";
2
+ import type { ActionRunner, AnyModel } from "./model.ts";
3
+ import { type Json, type Row } from "./values.ts";
4
+ /** A field or an input with its value in JSON form. */
5
+ export interface Named {
6
+ readonly name: string;
7
+ readonly value: Json;
8
+ }
9
+ /** A field an action changed, with its value before and after. */
10
+ export interface Change {
11
+ readonly field: string;
12
+ readonly before: Json;
13
+ readonly after: Json;
14
+ }
15
+ /**
16
+ * One action on a path: its id, its sentence as `label`, the input it was tried with, the
17
+ * fields it changed and the whole state after it.
18
+ */
19
+ export interface Step {
20
+ readonly action: string;
21
+ readonly label: string;
22
+ readonly input: readonly Named[];
23
+ readonly changes: readonly Change[];
24
+ readonly state: readonly Named[];
25
+ }
26
+ /** A start state and the actions that lead from it, as `earnest verify --json` prints a path. */
27
+ export interface Path {
28
+ readonly start: readonly Named[];
29
+ readonly steps: readonly Step[];
30
+ }
31
+ /**
32
+ * One rule's result. `path` is the shortest path to a state that breaks it, or `null`. A rule
33
+ * has no `kind`, `reason` or `repeatsFrom`. A rule about runs is listed after the rules with the
34
+ * `kind` `"eventually"`: its `path` leads into a run that never reaches the state it wants,
35
+ * `reason` says how the run goes on, and `repeatsFrom` is the position in `path.steps` of the
36
+ * first step of the loop that can repeat forever, left out when the run stays in the last state.
37
+ * A witness is listed last with the `kind` `"witness"`: its `path` is what was played until it
38
+ * broke, and `reason` says why it broke.
39
+ */
40
+ export interface RuleResult {
41
+ readonly id: string;
42
+ readonly says: string;
43
+ readonly verdict: Verdict;
44
+ readonly path: Path | null;
45
+ readonly kind?: "eventually" | "witness";
46
+ readonly reason?: string;
47
+ readonly repeatsFrom?: number;
48
+ }
49
+ /**
50
+ * `stuck`: the condition of every action is false and so is every end. `out-of-range`: an action
51
+ * gave a field a value outside its declaration. `fault`: a rule, the condition or the change of an
52
+ * action, or an end can't be evaluated in the state. A state where a condition or an end can't be
53
+ * evaluated is not stuck: nothing says that it should stop there or go on.
54
+ */
55
+ export type FindingKind = "stuck" | "out-of-range" | "fault";
56
+ /** A problem that is not a broken rule, with the shortest path to the first state showing it. */
57
+ export interface Finding {
58
+ readonly kind: FindingKind;
59
+ readonly message: string;
60
+ readonly path: Path;
61
+ }
62
+ /**
63
+ * What `explore` found. `states` counts distinct states, out-of-range ones included. `findings`
64
+ * holds at most one of each kind, in the order stuck, out-of-range, fault. `reason` says why an
65
+ * unfinished search stopped, and is `null` otherwise.
66
+ */
67
+ export interface Exploration {
68
+ readonly status: Status;
69
+ readonly states: number;
70
+ readonly rules: readonly RuleResult[];
71
+ readonly findings: readonly Finding[];
72
+ readonly reason: string | null;
73
+ }
74
+ /** The exports of a model file, by name: `import * as cart from "./cart.model.ts"`. */
75
+ export type Exports = Readonly<Record<string, unknown>>;
76
+ /**
77
+ * `maxStates` stops the search before it holds more distinct states than this; the default is
78
+ * 5,000,000. `exports` is the model file's exports, which give each action, rule and end its
79
+ * id: the name it is exported under. One that is not among them has its sentence as its id.
80
+ * `setup` is a setup declared on the model with `m.setup`: the search then starts from the
81
+ * setup's start states and plays the witnesses that name it, as `earnest verify` does on the
82
+ * setup's own result line. Without it the search starts where the model declares and plays the
83
+ * witnesses that name no setup.
84
+ */
85
+ export interface ExploreOptions {
86
+ readonly maxStates?: number;
87
+ readonly exports?: Exports;
88
+ readonly setup?: object;
89
+ }
90
+ /**
91
+ * Gives the function that names a part of a model: the name it is exported under in `exports`,
92
+ * or `fallback`, its sentence, when it is not exported there.
93
+ */
94
+ export declare const namer: (exports?: Exports) => ((part: object, fallback: string) => string);
95
+ /** What `attempt` gives: the result, or the sentence part saying why there is none. */
96
+ export type Attempt<T> = {
97
+ readonly fault: null;
98
+ readonly value: T;
99
+ } | {
100
+ readonly fault: string;
101
+ readonly value: null;
102
+ };
103
+ /**
104
+ * Runs part of a model and turns a fault into a value: reading a field of `null`, or using a
105
+ * value as something it is not. Any other error is a mistake in the model file and is thrown.
106
+ */
107
+ export declare const attempt: <T>(run: () => T) => Attempt<T>;
108
+ /**
109
+ * Applies an action and gives the next state, or the fault that stops it. Besides the faults of
110
+ * `attempt`, a next state that holds `NaN`, which `%` by zero gives, or a number too large for
111
+ * JavaScript to hold exactly is a fault.
112
+ */
113
+ export declare const nextState: (action: ActionRunner, state: Row, input: Row) => Attempt<Row>;
114
+ /** Every input an action is tried with, in the checker's order: the first input varies fastest. */
115
+ export declare const inputsOf: (action: ActionRunner) => readonly Row[];
116
+ /**
117
+ * Gives the start states of `model`, or of `setup`, a setup declared on it with `m.setup`: each
118
+ * start state of the model with the setup's fields put in, once each, in the model's order.
119
+ * `asker` names the function in the error thrown for a setup of another model.
120
+ */
121
+ export declare const startsOf: (model: AnyModel, setup: object | undefined, asker: string) => Row[];
122
+ /**
123
+ * Searches every state a model can reach, breadth first, and gives the count of distinct
124
+ * states, each rule's verdict with the shortest path to a state that breaks it, and the first
125
+ * stuck, out-of-range and fault findings. An end is asked only in a state where no action can
126
+ * happen. It visits states in the same order as
127
+ * `earnest verify`, so the two results can be compared. Pass the model file's exports as
128
+ * `exports` to get the same ids.
129
+ */
130
+ export declare const explore: (model: AnyModel, options?: ExploreOptions) => Exploration;