gdp-wired 0.45.0 → 0.46.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.
Files changed (120) hide show
  1. package/README.md +58 -7
  2. package/dist/core/bitsets.d.ts +2 -0
  3. package/dist/core/bitsets.js +23 -0
  4. package/dist/core/bmc.js +6 -2
  5. package/dist/core/c/reader.d.ts +9 -1
  6. package/dist/core/c/reader.js +423 -31
  7. package/dist/core/calendar.d.ts +29 -0
  8. package/dist/core/calendar.js +82 -0
  9. package/dist/core/cli.d.ts +3 -0
  10. package/dist/core/cli.js +204 -38
  11. package/dist/core/compose.js +3 -1
  12. package/dist/core/counts.d.ts +4 -1
  13. package/dist/core/counts.js +314 -85
  14. package/dist/core/cycles.js +8 -1
  15. package/dist/core/cyclic.d.ts +1 -0
  16. package/dist/core/cyclic.js +13 -7
  17. package/dist/core/data-synth.d.ts +3 -0
  18. package/dist/core/data-synth.js +252 -0
  19. package/dist/core/data.d.ts +2 -1
  20. package/dist/core/data.js +223 -24
  21. package/dist/core/discover.js +3 -1
  22. package/dist/core/draft.d.ts +19 -0
  23. package/dist/core/draft.js +53 -0
  24. package/dist/core/dsl.d.ts +37 -3
  25. package/dist/core/dsl.js +167 -26
  26. package/dist/core/effect.d.ts +1 -4
  27. package/dist/core/effect.js +1 -15
  28. package/dist/core/exists.d.ts +1 -0
  29. package/dist/core/exists.js +191 -16
  30. package/dist/core/extract-c.d.ts +2 -0
  31. package/dist/core/extract-c.js +169 -22
  32. package/dist/core/extract-check.d.ts +1 -0
  33. package/dist/core/extract-check.js +66 -0
  34. package/dist/core/extract-go-check.d.ts +1 -1
  35. package/dist/core/extract-go-check.js +2 -1
  36. package/dist/core/extract-go.d.ts +1 -0
  37. package/dist/core/extract-go.js +38 -4
  38. package/dist/core/extract-ir.d.ts +1 -0
  39. package/dist/core/extract-ir.js +15 -0
  40. package/dist/core/extract-jvm.d.ts +1 -1
  41. package/dist/core/extract-jvm.js +2 -0
  42. package/dist/core/extract-orm.d.ts +12 -0
  43. package/dist/core/extract-orm.js +244 -0
  44. package/dist/core/extract-print.js +20 -1
  45. package/dist/core/extract-py.d.ts +1 -0
  46. package/dist/core/extract-py.js +1 -1
  47. package/dist/core/extract-read.d.ts +17 -0
  48. package/dist/core/extract-read.js +5 -5
  49. package/dist/core/extract-rs.js +5 -1
  50. package/dist/core/extract-shapes.js +2 -0
  51. package/dist/core/extract-sol.d.ts +10 -1
  52. package/dist/core/extract-sol.js +70 -22
  53. package/dist/core/extract-step.d.ts +151 -1
  54. package/dist/core/extract-step.js +1232 -60
  55. package/dist/core/extract-swift.js +6 -2
  56. package/dist/core/extract.d.ts +8 -0
  57. package/dist/core/extract.js +61 -5
  58. package/dist/core/fiber-run.d.ts +5 -0
  59. package/dist/core/fiber-run.js +18 -0
  60. package/dist/core/infer.d.ts +4 -1
  61. package/dist/core/infer.js +918 -217
  62. package/dist/core/jvm/JavaReader.java +23 -6
  63. package/dist/core/jvm/Jvm.java +3 -0
  64. package/dist/core/jvm/KtReader.java +6 -5
  65. package/dist/core/laws.d.ts +10 -3
  66. package/dist/core/laws.js +193 -14
  67. package/dist/core/machine.d.ts +15 -1
  68. package/dist/core/machine.js +187 -15
  69. package/dist/core/nonterm.js +14 -1
  70. package/dist/core/orm/harness.js +61 -0
  71. package/dist/core/orm-fixtures/schema.prisma +5 -0
  72. package/dist/core/py/harness.py +183 -10
  73. package/dist/core/py/reader.py +234 -40
  74. package/dist/core/reader-fixtures/README.md +28 -0
  75. package/dist/core/reader-fixtures/c-693042.cpp +8 -0
  76. package/dist/core/reader-fixtures/go-685506.go +14 -0
  77. package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
  78. package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
  79. package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
  80. package/dist/core/reader-fixtures/swift-735726.swift +15 -0
  81. package/dist/core/reader-fixtures/swift-735990.swift +15 -0
  82. package/dist/core/reader-fixtures/swift-739158.swift +4 -0
  83. package/dist/core/reader-fixtures/swift-744834.swift +15 -0
  84. package/dist/core/reader-fixtures/swift-746946.swift +31 -0
  85. package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
  86. package/dist/core/relation.d.ts +1 -1
  87. package/dist/core/relation.js +29 -2
  88. package/dist/core/relational.js +4 -2
  89. package/dist/core/rs/src/main.rs +8 -2
  90. package/dist/core/sample-cache.d.ts +8 -0
  91. package/dist/core/sample-cache.js +46 -0
  92. package/dist/core/security.d.ts +38 -0
  93. package/dist/core/security.js +88 -0
  94. package/dist/core/sol/harness.py +57 -4
  95. package/dist/core/sol-concrete.d.ts +23 -0
  96. package/dist/core/sol-concrete.js +195 -0
  97. package/dist/core/solver.js +3 -1
  98. package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
  99. package/dist/core/system.js +1 -1
  100. package/dist/core/transfer.js +22 -9
  101. package/dist/core/translate.js +39 -10
  102. package/dist/core/watch.js +50 -5
  103. package/dist/interchange/format.js +11 -1
  104. package/dist/kernel/cdcl.d.ts +5 -0
  105. package/dist/kernel/cdcl.js +56 -9
  106. package/dist/kernel/epr.js +108 -26
  107. package/dist/kernel/kernel.d.ts +29 -1
  108. package/dist/kernel/kernel.js +325 -62
  109. package/dist/kernel/model-sequence.d.ts +3 -0
  110. package/dist/kernel/model-sequence.js +34 -0
  111. package/dist/kernel/prove.d.ts +10 -3
  112. package/dist/kernel/prove.js +332 -71
  113. package/dist/kernel/reader.d.ts +3 -0
  114. package/dist/kernel/reader.js +101 -14
  115. package/dist/kernel/share.d.ts +1 -0
  116. package/dist/kernel/share.js +27 -0
  117. package/dist/lean-kernel/emit.js +30 -37
  118. package/dist/lean-kernel/lean-terms.js +5 -0
  119. package/dist/lean-kernel/library.js +10 -10
  120. package/package.json +6 -1
@@ -474,11 +474,15 @@ function harnessFor(pkg, mod, read, opts) {
474
474
  fs.mkdirSync(path.dirname(path.join(work, l)), { recursive: true });
475
475
  node('node:fs').symlinkSync(to, path.join(work, l));
476
476
  }
477
- const built = buildCheck('swift build', () => cp.execFileSync(swiftOf(opts), ['build', '--product', 'GdpHarness', '--package-path', work], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 28, timeout: compileLimit(), killSignal: 'SIGKILL' }), e => `${e.stdout ?? ''}\n${e.stderr ?? ''}`.split('\n').filter(l => /\.swift:\d+:\d+: error:/.test(l)), l => { const m = /([^\s]+\.swift):(\d+):\d+: error:/.exec(l); if (!m)
477
+ // A source the reader can parse can still send swiftc into expensive type checking.
478
+ // Two buildCheck attempts must leave ample room below the reader fuzz's 300 s line.
479
+ const limit = Math.min(compileLimit(), 60_000);
480
+ const built = buildCheck('swift build', () => cp.execFileSync(swiftOf(opts), ['build', '--product', 'GdpHarness', '--package-path', work], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 28, timeout: limit, killSignal: 'SIGKILL' }), e => `${e.stdout ?? ''}\n${e.stderr ?? ''}`.split('\n').filter(l => /\.swift:\d+:\d+: error:/.test(l)), l => { const m = /([^\s]+\.swift):(\d+):\d+: error:/.exec(l); if (!m)
478
481
  return false; const r = path.relative(work, m[1]); if (r.startsWith('GdpHarness/'))
479
482
  return false; const n = own.get(r); return n === undefined || Number(m[2]) <= n; });
480
483
  if (!('ok' in built))
481
- return { cmd: 'false', args: [], hello: {}, error: built.why, kind: built.kind };
484
+ return { cmd: 'false', args: [], hello: {},
485
+ error: built.why + (built.kind === 'harness' ? `; Swift compiler build-check limit ${limit / 1000} s per attempt (source not verified)` : ''), kind: built.kind };
482
486
  const bin = cp.execFileSync(swiftOf(opts), ['build', '--package-path', work, '--show-bin-path'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
483
487
  return { cmd: `${bin}/GdpHarness`, args: [], hello: {} };
484
488
  }
@@ -4,18 +4,26 @@ import { type Model, Refusal, type Source, type Term } from './extract-read.js';
4
4
  import { type ReadOptions } from './extract-shapes.js';
5
5
  import { type Sorts } from './extract-print.js';
6
6
  import { type CheckOptions, type Evidence } from './extract-check.js';
7
+ import { type OrmOptions } from './extract-orm.js';
8
+ export type { OrmOptions } from './extract-orm.js';
7
9
  export { proveRule, proveSteps } from './dsl.js';
8
10
  export type ExtractOptions = Omit<ReadOptions, 'entry' | 'functions'> & {
9
11
  entry?: string | string[];
10
12
  /** @deprecated entry: [...] (the same: several functions over one record, the entry the first) */
11
13
  functions?: string[];
12
14
  file?: string;
15
+ orm?: OrmOptions;
13
16
  shape?: 'class' | 'functions';
14
17
  domains?: Record<string, 'nat' | 'int'>;
15
18
  check?: CheckOptions;
16
19
  };
17
20
  export type Extraction = {
18
21
  ok: boolean;
22
+ initializers?: {
23
+ entry: string;
24
+ name: string;
25
+ selectors: string[];
26
+ };
19
27
  quiet?: string;
20
28
  replay?: (run: {
21
29
  params: Record<string, number>;
@@ -18,7 +18,7 @@
18
18
  // read the same way (`extractXState`, a machine or a function that makes one, its actors, timers and eventless
19
19
  // transitions included).
20
20
  //
21
- // The subset: numbers (integers: a literal that isn't one is refused; division only as Math.floor or Math.ceil of
21
+ // The subset: numbers (integers: a literal that isn't one is refused; division only as Math.floor, ceil or trunc of
22
22
  // x / k for a constant k, a fraction being a binary float the code rounds; % by a constant of a natural), booleans,
23
23
  // string-literal unions, strings (set, compared, truthy where not empty), null and undefined where a value may be
24
24
  // missing, records and nested records (spreads, shorthand), Map and Record state keyed by numbers or strings (get,
@@ -45,6 +45,7 @@ import { Refusal, placed, sourceOf, syntaxError, tooDeep } from "./extract-read.
45
45
  import { isFactory, isSlice, readClass, readFactory, readFunctions, readSlice } from "./extract-shapes.js";
46
46
  import { kindOf, mapEmpty, mapKind, natOK, pb, pidx, pk, pnum, pterm, sortsOf } from "./extract-print.js";
47
47
  import { check } from "./extract-check.js";
48
+ import { extractOrm } from "./extract-orm.js";
48
49
  // (a rule read is proven from the same import: proveRule(x.rule!, [x.rule!.law(...)]))
49
50
  export { proveRule, proveSteps } from "./dsl.js";
50
51
  // The names of a model read from TypeScript (the state's layout, each request's arguments, each method's result).
@@ -100,6 +101,11 @@ export function extract(at, opts = {}) {
100
101
  const bad = syntaxError(code, file);
101
102
  if (bad)
102
103
  throw new Refusal(file, bad);
104
+ if (opts.orm) {
105
+ if (typeof at !== 'string' || at.includes('\n') || !/\.[cm]?[jt]sx?$/.test(at))
106
+ throw new Refusal(file, 'ORM checking requires the original module on disk');
107
+ return extractOrm(file, code, { ...opts, orm: opts.orm });
108
+ }
103
109
  const fns = Array.isArray(opts.entry) ? opts.entry : opts.functions;
104
110
  const o = { ...opts, entry: (Array.isArray(opts.entry) ? opts.entry[0] : opts.entry) ?? fns?.[0] ?? '', ...(fns ? { functions: fns } : {}) };
105
111
  model = o.entry ? readModel(code, file, o, opts.shape) : inferred(code, file, o, opts.shape);
@@ -209,7 +215,7 @@ function datesInRange(m, sorts) {
209
215
  // The module a user keeps: the rule, with what it was read from and how it was checked.
210
216
  export const toSource = (x) => x.source ?? '';
211
217
  // The source is the rule: it is evaluated with the builders, so what is checked is what is printed.
212
- const NAMES = ['rule', 'nat', 'int', 'bool', 'oneOf', 'str', 'record', 'when', 'min', 'max', 'all', 'any', 'not', 'yes', 'no', 'lit', 'intern', 'Int', 'desc'];
218
+ const NAMES = ['rule', 'nat', 'int', 'bool', 'oneOf', 'str', 'record', 'when', 'min', 'max', 'all', 'any', 'not', 'yes', 'no', 'lit', 'intern', 'Int', 'desc', 'everyKey'];
213
219
  function evaluate(body) {
214
220
  const f = compileFunction([...NAMES], `return ${body}`);
215
221
  const r = f(...NAMES.map(n => dsl[n]));
@@ -266,6 +272,10 @@ function builderOf(m, sorts) {
266
272
  const params = (t) => [...I.varsOf(t).vars].filter(n => m.params.some(p => p.name === n));
267
273
  const start = (v) => {
268
274
  const t = m.init[v.name], ps = params(t.e), fn = (x) => (ps.length ? `({${ps.join(', ')}}) => ${x}` : x);
275
+ // The kernel's start expressions read parameters only, not functions (including div/mod).
276
+ // A narrowing cast can introduce one even when the source spells no division.
277
+ walk(t.e, o => { if (o.op === 'divk' || o.op === 'modk')
278
+ throw new Refusal(m.file ?? m.entry, `${v.name}: division or remainder in an initializer (including a wrapping conversion) is outside the reader's start-expression subset`); });
269
279
  const at = pterm(t, P, ctx(), v.name);
270
280
  if (v.sort.k === 'num')
271
281
  return sorts.get(v.name) === 'nat' ? (ps.length ? fn(at) : at) : `int.from(${ps.length ? fn(at) : at})`;
@@ -287,7 +297,7 @@ function builderOf(m, sorts) {
287
297
  const vars = new Set(), maps = new Set();
288
298
  for (const x of xs)
289
299
  I.varsOf(x, vars, maps);
290
- return `{${[...new Set([...vars].filter(n => !m.leasts?.some(l => l.key === n)).map(leastOf)), ...maps].filter(n => n !== PASS).join(', ')}}`;
300
+ return `{${[...new Set([...vars].filter(n => !m.leasts?.some(l => l.key === n)).map(leastOf)), ...maps].filter(n => n !== PASS && n !== 'kl$' && n !== 'k$' && n !== 'j$').join(', ')}}`;
291
301
  };
292
302
  // The least keys: each where it holds, by what, read at the state before the step.
293
303
  if (m.leasts?.length) {
@@ -299,10 +309,53 @@ function builderOf(m, sorts) {
299
309
  const rec = (name, fs) => `record({${fs.map(f => `${f.name}: ${kindOf(f, sorts, `${name}.${f.name}`)}`).join(', ')}})`;
300
310
  for (const q of [...(m.seqs ?? []), ...(m.folds ?? []).map(d => ({ name: d.run, fields: d.fields }))])
301
311
  lines.push(` .carriesList(${JSON.stringify(q.name)}, ${rec(q.name, q.fields)})`);
312
+ // (a while loop's lists taken by an order: each one's held keys in it, and each key's place there)
313
+ for (const g of (m.folds ?? []).flatMap(d => d.loop?.drains ?? []))
314
+ lines.push(` .carriesList(${JSON.stringify(g.ord)}, record({k: nat}))`, ` .carries(${JSON.stringify(g.rk)})`);
302
315
  for (const d of m.folds ?? []) {
303
316
  const cell = (i, f) => ({ op: 'cell', map: d.run, key: { op: 'num', e: i }, field: f.name, ...(f.sort.k === 'choice' ? { values: f.sort.values } : {}) });
304
317
  const eq = (i, f, t) => (t.s === 'num' ? I.cmp('=', cell(i, f), t.e) : t.s === 'bool' ? I.and(I.or(I.not(cell(i, f)), t.e), I.or(cell(i, f), I.not(t.e))) : t.s === 'str' ? I.keq(cell(i, f), t.e) : I.leq(cell(i, f), t.e));
305
- const start = I.and(...d.fields.map(f => eq(I.num(0), f, d.init[f.name]))), step = I.and(...d.fields.map(f => eq(I.add(I.nvar(PASS), I.num(1)), f, d.step[f.name])));
318
+ const start = I.and(...d.fields.filter(f => d.init[f.name]).map(f => eq(I.num(0), f, d.init[f.name]))), step = I.and(...d.fields.filter(f => d.step[f.name]).map(f => eq(I.add(I.nvar(PASS), I.num(1)), f, d.step[f.name])));
319
+ if (d.loop?.cond && d.loop.drains) {
320
+ // A while loop's over lists by an order: its passes, each where its condition holds and none ended the loop, then
321
+ // the first where not; each list's held keys in the order (increasing, each held, every held one at its place,
322
+ // tying it), and no two that tie where the loop runs.
323
+ const l = d.loop, cond = l.cond, len = d.len, endC = I.substN(cond, PASS, len);
324
+ const text = `all(${d.run}_len.eq(${pnum(I.add(len, I.num(1)), P, ctx())}), ${pb(start, P, ctx())}, ${d.run}.every((_x, ${PASS}) => ${PASS}.lt(${pnum(len, P, ctx())}).implies(${pb(I.and(step, cond), P, ctx())})), ${pb(I.not(endC), P, ctx())})`;
325
+ const env = envOf(start, step, cond, endC).slice(1, -1).split(', ').filter(Boolean);
326
+ lines.push(` .assume((${withChoices(`{${[...new Set([...env, d.run, `${d.run}_len`])].join(', ')}}`, text, P)}) => ${text})`);
327
+ for (const g of l.drains) {
328
+ const ordAt = (x) => ({ op: 'cell', map: g.ord, key: { op: 'num', e: x }, field: 'k' }), byAt = (x) => g.by.map(b => ({ ...b, e: I.substN(b.e, 'kl$', x) }));
329
+ const lt = (a, b) => a.reduceRight((acc, x, j) => { const y = b[j]; return I.or(x.desc ? I.cmp('<', y.e, x.e) : I.cmp('<', x.e, y.e), I.and(I.cmp('=', x.e, y.e), acc)); }, I.F);
330
+ const same = (a, b) => I.and(...a.map((x, j) => I.cmp('=', x.e, b[j].e)));
331
+ const iv = I.nvar('i$'), jv = I.nvar('j$'), kv = I.nvar('kl$'), cnt = I.nvar(`${g.ord}_len`), place = { op: 'cell', map: g.rk, key: { op: 'num', e: kv }, field: '$item' };
332
+ const heldAt = (x) => I.substN(g.held, 'kl$', x);
333
+ const inc = I.or(I.not(I.and(I.cmp('<', iv, jv), I.cmp('<', jv, cnt))), lt(byAt(ordAt(iv)), byAt(ordAt(jv))));
334
+ const held = I.or(I.not(I.cmp('<', iv, cnt)), heldAt(ordAt(iv)));
335
+ const all = I.or(I.not(g.held), I.and(I.cmp('<', place, cnt), same(byAt(ordAt(place)), g.by)));
336
+ sorts.set('j$', 'nat');
337
+ // (two held keys at one place are one: with the list increasing, every held key is at the place of its own, and
338
+ // two items that tie under the order have no list, so the rule refuses there, an edge the check counts apart)
339
+ const rkAt = (x) => ({ op: 'cell', map: g.rk, key: { op: 'num', e: x }, field: '$item' });
340
+ const one = I.or(I.not(I.and(g.held, heldAt(jv), I.cmp('=', rkAt(kv), rkAt(jv)))), I.cmp('=', kv, jv));
341
+ // (all of it only where the loop runs: the request its method's, on its branch)
342
+ const gate = l.entry && !(l.entry.op === 'const' && l.entry.v) ? l.entry : undefined;
343
+ for (const [vs, c] of [['i$, j$', inc], ['i$', held], ['kl$', all], ['kl$, j$', one]]) {
344
+ const t0 = `everyKey((${vs}) => ${pb(c, P, ctx())})`, t = gate ? `any(${pb(I.not(gate), P, ctx())}, ${t0})` : t0;
345
+ const e = envOf(c, ...(gate ? [gate] : [])).slice(1, -1).split(', ').filter(n => Boolean(n) && n !== 'j$');
346
+ lines.push(` .assume((${withChoices(`{${[...new Set([...e, g.ord, `${g.ord}_len`])].join(', ')}}`, t, P)}) => ${t})`);
347
+ }
348
+ }
349
+ continue;
350
+ }
351
+ if (d.back) {
352
+ // (from the last place down: the start at the length, each pass's output at its own place)
353
+ const step2 = I.and(...d.fields.filter(f => d.step[f.name]).map(f => eq(I.nvar(PASS), f, d.step[f.name]))), start2 = I.and(...d.fields.filter(f => d.init[f.name]).map(f => eq(d.len, f, d.init[f.name])));
354
+ const text = `all(${d.run}_len.eq(${pnum(I.add(d.len, I.num(1)), P, ctx())}), ${pb(start2, P, ctx())}, ${d.run}.every((_x, ${PASS}) => ${PASS}.lt(${pnum(d.len, P, ctx())}).implies(${pb(step2, P, ctx())})))`;
355
+ const env = envOf(start2, step2, d.len).slice(1, -1).split(', ').filter(Boolean);
356
+ lines.push(` .assume((${withChoices(`{${[...new Set([...env, d.run, `${d.run}_len`])].join(', ')}}`, text, P)}) => ${text})`);
357
+ continue;
358
+ }
306
359
  // (the passes over the run's places: one past the list's length, a carried list's or one of the state's)
307
360
  const len = I.add(d.len, I.num(1)), text = `all(${d.run}_len.eq(${pnum(len, P, ctx())}), ${pb(start, P, ctx())}, ${d.run}.every((_x, ${PASS}) => ${PASS}.lt(${pnum(d.len, P, ctx())}).implies(${pb(step, P, ctx())})))`;
308
361
  const env = envOf(start, step, d.len).slice(1, -1).split(', ').filter(Boolean);
@@ -337,7 +390,7 @@ function builderOf(m, sorts) {
337
390
  // Several keys written: every key at once, each cell the last write at it (k$, the key, a natural).
338
391
  const k = { op: 'num', e: I.nvar('k$') }, ws = allW(w);
339
392
  sorts.set('k$', 'nat');
340
- const at = (x) => I.and(x.when ?? I.T, I.keq(k, x.key));
393
+ const at = (x) => I.and(x.when ?? I.T, x.each ? I.T : I.keq(k, x.key));
341
394
  const has = ws.reduce((acc, x) => I.bite(at(x), x.has, acc), { op: 'cell', map: n, key: k, field: 'has' });
342
395
  const vals = d.fields.map(f => {
343
396
  const base = f.sort.k === 'num' ? { s: 'num', e: { op: 'cell', map: n, key: k, field: f.name } } : f.sort.k === 'choice' ? { s: 'choice', e: { op: 'cell', map: n, key: k, field: f.name, values: f.sort.values } } : { s: 'bool', e: { op: 'cell', map: n, key: k, field: f.name } };
@@ -444,6 +497,9 @@ function hoist(m, P, roots) {
444
497
  const node = hoistNodes.get(k), size = k.length;
445
498
  if ((count.get(k) ?? 0) < 2 || size < 60 || isChoice(node))
446
499
  continue;
500
+ // (a term over a bound name (a key every key is written at, a pass) is printed where that name is bound)
501
+ if (/"name":"(k\$|kl\$|i\$)"/.test(k))
502
+ continue;
447
503
  // (a product of integers kept at 0 or above only by the conditions the path is under: printed where it is read,
448
504
  // under them, never hoisted out of them)
449
505
  let guarded = false;
@@ -0,0 +1,5 @@
1
+ import type { Extraction } from './extract.js';
2
+ export declare function fiberRun(x: Extraction, run: {
3
+ params: Record<string, number>;
4
+ trace: Record<string, unknown>[];
5
+ }, renderCall?: (q: Record<string, unknown>) => string): string[];
@@ -0,0 +1,18 @@
1
+ // Display a concurrent source witness without losing fiber identities or operation boundaries.
2
+ // Kept separate from the TypeScript reader so other CLI frontends do not acquire its optional dependency.
3
+ import { interpret } from "./machine.js";
4
+ export function fiberRun(x, run, renderCall) {
5
+ const fibers = x.fibers ?? [], r = x.rule;
6
+ const go = interpret(r.machine), ps = r.encodeParams(run.params), method = new Map(r.parts.inputs).get('method');
7
+ let st = go.init(ps);
8
+ return run.trace.map(q => {
9
+ const f = Number(q.fiber), pc = st.maps.__gdp_pc?.get(f) ?? 0, m = method ? method.decode('method', q) : x.model?.events[0]?.call ?? 'step';
10
+ st = go.step(ps, st, q);
11
+ if (pc === 0) {
12
+ const sp = fibers.find(s2 => s2.name === m), args = (x.names ?? []).filter(n => n.role === 'input' && n.method === m && n.rule in q).map(n => `${n.code.split('.').pop()} = ${String(q[n.rule])}`);
13
+ return `fiber ${f}: ${renderCall ? renderCall(q) : `${m}(${args.join(', ')})`}${sp ? `, its step 1 of ${sp.steps}` : ''}`;
14
+ }
15
+ const sp = fibers.find(s2 => pc > s2.base && pc <= s2.base + s2.steps);
16
+ return `fiber ${f}: ${sp.name}, its step ${pc - sp.base} of ${sp.steps}`;
17
+ });
18
+ }
@@ -1,6 +1,7 @@
1
- import { type Law, type Machine, type State } from './machine.js';
1
+ import { type Law, type Machine, type Request, type State } from './machine.js';
2
2
  import { type StepLaw, type Verdict, proveRule } from './dsl.js';
3
3
  type AnyRule = Parameters<typeof proveRule>[0];
4
+ type Env = Record<string, number>;
4
5
  export type InferOptions = {
5
6
  ms?: number;
6
7
  runs?: number;
@@ -50,5 +51,7 @@ export declare const inferRates: {
50
51
  efull: number;
51
52
  };
52
53
  export declare const inferRuns = 16000;
54
+ export declare function constantsOf(m: Machine, laws: Law[]): number[];
55
+ export declare function domainStep(m: Machine, most?: number): ((params: Env, st: State, input: Request) => State | undefined) | undefined;
53
56
  export declare function inferLaws(target: AnyRule | Machine, laws: Law[], stepLaws?: StepLaw[], opts?: InferOptions): Inferred;
54
57
  export {};