gdp-wired 0.50.2 → 0.50.4

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 (69) hide show
  1. package/README.md +8 -2
  2. package/dist/core/agent-consult/cli.d.ts +2 -0
  3. package/dist/core/agent-consult/cli.js +19 -0
  4. package/dist/core/agent-consult/protocol.d.ts +93 -0
  5. package/dist/core/agent-consult/protocol.js +154 -0
  6. package/dist/core/agent-consult/service.d.ts +435 -0
  7. package/dist/core/agent-consult/service.js +84 -0
  8. package/dist/core/agent-consult/session.d.ts +13 -0
  9. package/dist/core/agent-consult/session.js +163 -0
  10. package/dist/core/agent-consult/source-service.d.ts +83 -0
  11. package/dist/core/agent-consult/source-service.js +51 -0
  12. package/dist/core/agent-consult/tsconfig.json +5 -0
  13. package/dist/core/agent-consult/worker.d.ts +1 -0
  14. package/dist/core/agent-consult/worker.js +17 -0
  15. package/dist/core/agent-consult/workspace.d.ts +27 -0
  16. package/dist/core/agent-consult/workspace.js +66 -0
  17. package/dist/core/agent-consult.d.ts +8 -0
  18. package/dist/core/agent-consult.js +6 -0
  19. package/dist/core/cli.d.ts +17 -1
  20. package/dist/core/cli.js +174 -68
  21. package/dist/core/discover.d.ts +6 -1
  22. package/dist/core/discover.js +54 -7
  23. package/dist/core/dsl-deadline.d.ts +3 -0
  24. package/dist/core/dsl-deadline.js +26 -2
  25. package/dist/core/dsl.d.ts +3 -1
  26. package/dist/core/dsl.js +93 -30
  27. package/dist/core/effect.d.ts +12 -0
  28. package/dist/core/effect.js +26 -9
  29. package/dist/core/ex/harness.exs +171 -5
  30. package/dist/core/extract-c.js +63 -6
  31. package/dist/core/extract-check.d.ts +5 -1
  32. package/dist/core/extract-check.js +28 -10
  33. package/dist/core/extract-go-check.js +127 -1
  34. package/dist/core/extract-go.js +8 -2
  35. package/dist/core/extract-jvm.js +2 -2
  36. package/dist/core/extract-rs.js +51 -5
  37. package/dist/core/extract-step.js +40 -6
  38. package/dist/core/extract-swift.js +47 -3
  39. package/dist/core/extract.d.ts +8 -0
  40. package/dist/core/infer.d.ts +8 -0
  41. package/dist/core/infer.js +133 -16
  42. package/dist/core/jvm/Harness.java +135 -3
  43. package/dist/core/jvm/Rt.java +66 -4
  44. package/dist/core/laws.js +51 -10
  45. package/dist/core/native-law.d.ts +3 -1
  46. package/dist/core/native-law.js +126 -14
  47. package/dist/core/native-observations.d.ts +20 -0
  48. package/dist/core/native-observations.js +41 -0
  49. package/dist/core/native-wire.d.ts +1 -0
  50. package/dist/core/native-wire.js +16 -2
  51. package/dist/core/py/harness.py +21 -4
  52. package/dist/core/rb/harness.rb +178 -9
  53. package/dist/core/search-termination.d.ts +35 -0
  54. package/dist/core/search-termination.js +13 -0
  55. package/dist/core/search-watchdog.d.ts +8 -0
  56. package/dist/core/search-watchdog.js +34 -0
  57. package/dist/core/source-check.d.ts +3 -0
  58. package/dist/core/swift/Harness.swift +65 -4
  59. package/dist/core/swift/Main.swift +27 -4
  60. package/dist/core/wall.d.ts +3 -1
  61. package/dist/core/wall.js +7 -4
  62. package/dist/core/work-refusal.d.ts +3 -0
  63. package/dist/core/work-refusal.js +8 -0
  64. package/dist/kernel/prove.d.ts +2 -0
  65. package/dist/kernel/prove.js +13 -5
  66. package/docs/agent-consult-workspace-check.md +118 -0
  67. package/docs/agent-consult.md +151 -0
  68. package/examples/agent-consult.json +22 -0
  69. package/package.json +11 -3
package/dist/core/cli.js CHANGED
@@ -9,10 +9,20 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
9
9
  };
10
10
  import { fiberRun } from "./fiber-run.js";
11
11
  import { securityTemplates } from "./security.js";
12
- import { proveLeadsTo, proveRule, proveSteps } from "./dsl.js";
12
+ import { proveLeadsTo as rawLeadsTo, proveRule as rawRule, proveSteps as rawSteps } from "./dsl.js";
13
+ import { traceNow, withTraceWorkScope } from "./trace-clock.js";
14
+ import { terminationWhy } from "./search-termination.js";
15
+ import { validateWatchdog } from "./search-watchdog.js";
13
16
  import { sourceDiagnostic } from "./source-diagnostic.js";
14
17
  import { LawError, buildLaw, buildLeadsTo, buildTwoRuns, citesIn, isLeadsTo, isTwoRuns, lawsIn, namesWithClock } from "./laws.js";
15
- import { certify, proveTwoRuns } from "./relational.js";
18
+ import { certify, proveTwoRuns as rawTwoRuns } from "./relational.js";
19
+ let syncControl;
20
+ const admitted = (f) => syncControl ? syncControl.invoke(f) : f();
21
+ const proveRule = (...a) => admitted(() => rawRule(...a));
22
+ const proveSteps = (...a) => admitted(() => rawSteps(...a));
23
+ const proveLeadsTo = (...a) => admitted(() => rawLeadsTo(...a));
24
+ const proveTwoRuns = (...a) => admitted(() => rawTwoRuns(...a));
25
+ const cliNow = () => syncControl ? traceNow() : Date.now();
16
26
  import { contend, envOf, inEnv, shrinkRun } from "./system.js";
17
27
  const proc = globalThis.process;
18
28
  const fs = proc.getBuiltinModule('node:fs'), path = proc.getBuiltinModule('node:path');
@@ -25,7 +35,7 @@ const SGR = { green: 32, red: 31, yellow: 33, dim: 2 };
25
35
  const paint = (c, s) => (tint && s !== '' ? `\x1b[${SGR[c]}m${s}\x1b[0m` : String(s));
26
36
  const VERDICT = { proven: 'green', broken: 'red', unknown: 'yellow', 'not read': 'yellow' };
27
37
  function args(argv) {
28
- const o = { ms: 10_000, propose: true }, targets = [];
38
+ const o = { propose: true }, targets = [];
29
39
  let cmd = '';
30
40
  for (let i = 0; i < argv.length; i++) {
31
41
  const a = argv[i];
@@ -40,7 +50,7 @@ function args(argv) {
40
50
  else if (a.startsWith('--')) {
41
51
  const [k, inline] = a.slice(2).split('='), v = inline ?? argv[++i] ?? '';
42
52
  const key = k.replace(/-(\w)/g, (_, c) => c.toUpperCase());
43
- o[key] = key === 'methods' ? v.split(',') : key === 'ms' ? Number(v) : v;
53
+ o[key] = key === 'methods' ? v.split(',') : key === 'ms' || key === 'work' || key === 'watchdogMs' ? Number(v) : v;
44
54
  }
45
55
  else if (!cmd)
46
56
  cmd = a;
@@ -103,7 +113,8 @@ async function extractOne(t, o) {
103
113
  }
104
114
  // A TypeScript file's relative imports, read beside it as TypeScript resolves them (two deep, at most 12 files), by their
105
115
  // path from the file's directory: their classes and functions are the code's own, read and inlined, not another module's.
106
- function relativeImports(entry) {
116
+ function relativeImports(entry, guard) {
117
+ guard?.(entry);
107
118
  const out = {}, seen = new Set([entry]), queue = [[entry, 1]], dir = path.dirname(entry);
108
119
  while (queue.length && Object.keys(out).length < 12) {
109
120
  const [from, depth] = queue.shift();
@@ -112,6 +123,7 @@ function relativeImports(entry) {
112
123
  const hit = [base, ...['.ts', '.tsx', '.js', '.jsx', '.mjs'].map(x => `${bare}${x}`), ...['/index.ts', '/index.tsx', '/index.js'].map(x => `${base}${x}`)].find(c => fs.existsSync(c) && !fs.statSync(c).isDirectory());
113
124
  if (!hit || seen.has(hit) || Object.keys(out).length >= 12)
114
125
  continue;
126
+ guard?.(hit);
115
127
  seen.add(hit);
116
128
  out[path.relative(dir, hit)] = fs.readFileSync(hit, 'utf8');
117
129
  if (depth < 2)
@@ -191,6 +203,10 @@ async function extractWith(t, o) {
191
203
  }
192
204
  }
193
205
  export function configFor(from) {
206
+ // Workspace initial profile deliberately has no project-config overrides/interpreters.
207
+ // Do not even search ancestors outside the server-authorized workspace.
208
+ if (syncControl)
209
+ return { all: {}, rules: {} };
194
210
  // (the first of the three in a directory that holds gdp's options)
195
211
  const holder = (d) => ['gdp.toml', 'pyproject.toml', 'package.json'].find(f => fs.existsSync(path.join(d, f)) && (f === 'gdp.toml' || (f === 'pyproject.toml' ? /^\[tool\.gdp\b/m : /"gdp"\s*:/).test(fs.readFileSync(path.join(d, f), 'utf8'))));
196
212
  const dir = up(from, d => !!holder(d));
@@ -284,9 +300,14 @@ const translationOf = (v) => ({
284
300
  ...(v.kernelProven !== undefined ? { kernelProven: v.kernelProven } : {}),
285
301
  ...(v.translationWitness ? { translationWitness: sourceDiagnostic(v.translationWitness) } : {}),
286
302
  });
287
- // Each initializer is a separate scope, with its own original-code replay and laws. Never choose one
288
- // overload on the caller's behalf or let a successful variant hide another variant's refusal.
289
- async function expandInitializers(t, o, laws, rows) {
303
+ // Only structured provenance can explain cancellation. A semantic unknown whose
304
+ // text happens to say "time" or "work" is not a stopped search. Native refusal
305
+ // remains the primary diagnostic, with any search stop carried separately.
306
+ const searchOf = (v) => v.stopped && v.termination && !(v.proven && v.checked) && !v.run
307
+ ? { stopped: true, termination: v.termination, ...(v.context ? { context: v.context } : {}) } : {};
308
+ const whyOf = (v, semantic) => searchOf(v).termination && v.translation !== 'unchecked' && v.translation !== 'error'
309
+ ? terminationWhy(v.termination) : semantic;
310
+ function* expandInitializers(t, o, laws, rows) {
290
311
  if (!rows.some(r => r.x.initializers))
291
312
  return rows;
292
313
  const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
@@ -315,27 +336,27 @@ async function expandInitializers(t, o, laws, rows) {
315
336
  const opts = merge(merge({ ...shared, keep }, cfg.rules[entry] || {}), flags);
316
337
  // A rule-specific constructor choice discovered after entry inference still takes precedence.
317
338
  if (opts.ctor !== undefined) {
318
- out.push({ entry, x: await extractOne(t, { ...opts, entry: variants.entry }) });
339
+ out.push({ entry, x: yield { target: t, options: { ...opts, entry: variants.entry } } });
319
340
  continue;
320
341
  }
321
342
  for (const ctor of [...new Set(variants.selectors)]) {
322
- const x = await extractOne(t, { ...opts, entry: variants.entry, ctor });
343
+ const x = yield { target: t, options: { ...opts, entry: variants.entry, ctor } };
323
344
  x.notes.push(`initializer ${ctor}: separate scope; every initializer is required for coverage of the class`);
324
345
  out.push({ entry, ctor, x });
325
346
  }
326
347
  }
327
348
  return out;
328
349
  }
329
- async function rulesOf(t, o, laws) {
330
- const got = await rulesOf0(t, o, laws);
350
+ function* rulesOf(t, o, laws) {
351
+ const got = yield* rulesOf0(t, o, laws);
331
352
  if (o.entry)
332
- return expandInitializers(t, o, laws, got);
353
+ return yield* expandInitializers(t, o, laws, got);
333
354
  // (a function that is a request of a rule read, a C file's globals', is read with it)
334
355
  const evs = (x) => { const s = x.model?.inputs?.find(v => v.name === (x.names ?? []).find(n => n.role === 'method')?.rule)?.sort; return s?.k === 'choice' ? s.values ?? [] : []; };
335
356
  const have = new Set(got.flatMap(r => [r.entry, r.x.model?.name, r.x.initializers?.name, ...(r.x.ok ? [...(r.x.names ?? []).map(n => n.method), ...evs(r.x)] : [])].filter((n) => !!n)));
336
357
  const more = [...new Set(laws.map(l => l.cls ?? l.fn).filter((n) => !!n && !have.has(n)))];
337
358
  if (!more.length)
338
- return expandInitializers(t, o, laws, got);
359
+ return yield* expandInitializers(t, o, laws, got);
339
360
  const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
340
361
  void _j;
341
362
  void _m;
@@ -348,11 +369,13 @@ async function rulesOf(t, o, laws) {
348
369
  void _k;
349
370
  void _f;
350
371
  const keep = [...new Set(laws.flatMap(l => l.expr.match(/[A-Za-z_]\w*(?:::[A-Za-z_]\w*)*/g) ?? []).flatMap(k => (k.includes('::') ? [k, ...k.split('::')] : [k])))];
351
- const extra = await Promise.all(more.map(async (entry) => ({ entry, x: await extractOne(t, { ...merge(merge({ ...shared, keep }, cfg.rules[entry] || {}), flags), entry }) })));
372
+ const extra = [];
373
+ for (const entry of more)
374
+ extra.push({ entry, x: yield { target: t, options: { ...merge(merge({ ...shared, keep }, cfg.rules[entry] || {}), flags), entry } } });
352
375
  // (the first rule, read with no entry named, kept only where it read something or nothing else was)
353
- return expandInitializers(t, o, laws, [...got.filter(r => r.x.ok || r.entry || !extra.length), ...extra]);
376
+ return yield* expandInitializers(t, o, laws, [...got.filter(r => r.x.ok || r.entry || !extra.length), ...extra]);
354
377
  }
355
- async function rulesOf0(t, o, laws) {
378
+ function* rulesOf0(t, o, laws) {
356
379
  const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
357
380
  void _j;
358
381
  void _m;
@@ -369,24 +392,27 @@ async function rulesOf0(t, o, laws) {
369
392
  // (the names the laws read, so an argument a law reads stays in the rule though the code ignores it)
370
393
  const keep = [...new Set(laws.flatMap(l => l.expr.match(/[A-Za-z_]\w*(?:::[A-Za-z_]\w*)*/g) ?? []).flatMap(k => (k.includes('::') ? [k, ...k.split('::')] : [k])))];
371
394
  const optsFor = (entry) => merge(merge({ ...shared, keep }, (entry && cfg.rules[entry]) || {}), flags);
372
- const one = async (entry) => {
373
- const x = await extractOne(t, { ...optsFor(entry), ...(entry ? { entry } : {}) }), found = x.model?.name;
374
- return !entry && found && cfg.rules[found] ? { entry: found, x: await extractOne(t, { ...optsFor(found), entry: found }) } : { entry, x };
395
+ const one = function* (entry) {
396
+ const x = yield { target: t, options: { ...optsFor(entry), ...(entry ? { entry } : {}) } };
397
+ const found = x.model?.name;
398
+ return !entry && found && cfg.rules[found] ? { entry: found, x: yield { target: t, options: { ...optsFor(found), entry: found } } } : { entry, x };
375
399
  };
400
+ const manyOf = function* (entries) { const rows = []; for (const entry of entries)
401
+ rows.push(yield* one(entry)); return rows; };
376
402
  const given = o.entry ?? cfg.all.entry;
377
403
  if (given)
378
- return [await one(given)];
404
+ return [yield* one(given)];
379
405
  if (t.lang === 'ts' || t.lang === 'cpp') {
380
406
  const code = t.files.map(f => fs.readFileSync(f, 'utf8')).join('\n');
381
407
  const re = t.lang === 'cpp' ? /^\s*(?:class|struct)\s+(\w+)\s*(?::[^{]*)?\{/gm : /export\s+(?:default\s+)?(?:abstract\s+)?class\s+(\w+)|export\s+(?:const|function)\s+(\w+)/g;
382
408
  // (C++: a class its source file defines methods of, `Alarm::detected(...) {`, declared in its header)
383
409
  const defs = t.lang === 'cpp' ? [...code.matchAll(/^[\w:<>*&\s]*?\b(\w+)::~?\w+\s*\([^;]*?\)\s*(?:const\s*)?(?::[^{;]*)?\{/gm)].map(m => m[1]) : [];
384
410
  const cands = [...new Set([...[...code.matchAll(re)].map(m => m[1] ?? m[2]), ...defs])];
385
- const all = await Promise.all(cands.map(c => one(c)));
411
+ const all = yield* manyOf(cands);
386
412
  const good = all.filter(r => r.x.ok);
387
413
  return good.length ? good : all.length ? all : [{ x: { ok: false, refusals: [{ where: t.at, what: 'no class or exported function to read: name the entry (--entry)' }], notes: [] } }];
388
414
  }
389
- const first = await one();
415
+ const first = yield* one();
390
416
  if (first.x.ok)
391
417
  return [first];
392
418
  // (refused with no entry named: the rules gdp.toml names that the code has, each with its options)
@@ -396,7 +422,7 @@ async function rulesOf0(t, o, laws) {
396
422
  const many = /several (?:classes|structs) (?:write their state|written by the file's functions) \(([^)]*)\)/.exec(first.x.refusals[0]?.what ?? '')?.[1].split(', ') ?? [];
397
423
  const fns0 = [...new Set(laws.filter(l => !l.cls && l.fn).map(l => l.fn))];
398
424
  if (named.length)
399
- return Promise.all([...new Set([...many, ...named, ...fns0])].map(k => one(k)));
425
+ return yield* manyOf([...new Set([...many, ...named, ...fns0])]);
400
426
  // (a contract's file names its contracts: refused with none named, the refusal is the rule's)
401
427
  if (t.lang === 'solidity')
402
428
  return [first];
@@ -404,7 +430,7 @@ async function rulesOf0(t, o, laws) {
404
430
  const what = first.x.refusals[0]?.what ?? '';
405
431
  const several = /several (?:classes|structs) (?:write their state|written by the file's functions) \(([^)]*)\)/.exec(what)?.[1].split(', ') ?? [];
406
432
  const fns = [...new Set(laws.filter(l => !l.cls && l.fn).map(l => l.fn))];
407
- return several.length || fns.length ? Promise.all([...several, ...fns].map(c => one(c))) : [first];
433
+ return several.length || fns.length ? yield* manyOf([...several, ...fns]) : [first];
408
434
  }
409
435
  // (a class statement's name: its keyword at the start of a line, after modifiers; never a word in a comment)
410
436
  const classAt = (line) => {
@@ -503,15 +529,71 @@ export function scoped(file) {
503
529
  return { ...l, ...(cls ? { cls } : {}), ...(fn ? { fn } : {}) };
504
530
  });
505
531
  }
532
+ // Both drivers consume the same enumeration, configuration and proof/proposal algorithm.
506
533
  export async function checkTarget(t, o) {
534
+ return drivePipeline(checkPipeline(t, o));
535
+ }
536
+ async function drivePipeline(pipeline) {
537
+ let next = pipeline.next();
538
+ while (!next.done) {
539
+ const job = next.value;
540
+ if ('target' in job)
541
+ next = pipeline.next(await extractOne(job.target, job.options));
542
+ else {
543
+ const { withLemmas } = await import("./effect.js"), w = withLemmas(job.lemmas, { ...(job.work === undefined ? { ms: job.ms } : { work: job.work }), watchdogMs: job.watchdogMs });
544
+ job.output.supportAttempts = w.attempts.map(a => ({ name: a.name, ...(a.verdict ? { proven: a.verdict.proven, checked: a.verdict.checked, ...searchOf(a.verdict), ...(a.verdict.why ? { why: a.verdict.why } : {}), ...(a.verdict.translation ? { translation: a.verdict.translation } : {}), ...(a.verdict.kernelProven === undefined ? {} : { kernelProven: a.verdict.kernelProven }) } : {}), ...(a.failure ? { failure: a.failure } : {}) }));
545
+ job.output.notes = [...job.output.notes, ...w.proven.map(n => `lemma proven, beside every law: ${n}`), ...w.unproven.map(n => `lemma not proven (left out): ${n}`)];
546
+ next = pipeline.next(w.x);
547
+ }
548
+ }
549
+ return next.value;
550
+ }
551
+ // Initialization only: no source reads/extraction/proof before the caller's counted scope.
552
+ // Async-only Effect/XState and package-oriented front ends intentionally remain unsupported.
553
+ export async function prepareFileCheck() {
554
+ const [{ extractPython }, { extract }] = await Promise.all([import("./extract-py.js"), import("./extract.js")]);
555
+ return (file, root, control, guard) => {
556
+ if (syncControl)
557
+ throw new Error('nested synchronous source checks are unsupported');
558
+ const lang = EXT[path.extname(file)];
559
+ if (lang !== 'python' && lang !== 'ts')
560
+ throw new Error('workspace check supports Python and plain TypeScript/JavaScript files only');
561
+ syncControl = control;
562
+ try {
563
+ return withTraceWorkScope(() => {
564
+ guard(file);
565
+ const pipeline = checkPipeline({ lang, at: file, files: [file] }, { ms: 2000, propose: true });
566
+ let next = pipeline.next();
567
+ while (!next.done) {
568
+ const job = next.value;
569
+ if (!('target' in job))
570
+ throw new Error('Effect lemmas require an async-only source engine');
571
+ guard(job.target.at);
572
+ const code = fs.readFileSync(job.target.at, 'utf8');
573
+ if (lang === 'ts' && /(?:from\s+|import\s*\(\s*|require\s*\(\s*|import\s*)['"](?:effect|xstate)(?:[/'"])/.test(code))
574
+ throw new Error('Effect/XState workspace checks require an async-only source engine');
575
+ const options = { ...job.options, root };
576
+ const x = control.invoke(() => lang === 'python' ? extractPython(job.target.at, options) : extract({ code, file: job.target.at }, { ...options, files: relativeImports(job.target.at, guard) }));
577
+ next = pipeline.next(x);
578
+ }
579
+ guard(file);
580
+ return next.value;
581
+ });
582
+ }
583
+ finally {
584
+ syncControl = undefined;
585
+ }
586
+ };
587
+ }
588
+ function* checkPipeline(t, o) {
507
589
  const laws = t.files.flatMap(scoped), cites = t.files.flatMap(f => citesIn(fs.readFileSync(f, 'utf8'), path.basename(f)));
508
- const rules = await rulesOf(t, o, laws);
590
+ const rules = yield* rulesOf(t, o, laws);
509
591
  const outs = [];
510
592
  // (the clock's unit, for durations in a law: the language's clock, or clock = "s" | "ms" in gdp.toml or --clock)
511
593
  const unit = o.clock ?? configFor(t.lang === 'go' || t.lang === 'rust' || fs.statSync(t.at).isDirectory() ? t.at : path.dirname(t.at)).all.clock ?? CLOCK[t.lang];
512
594
  const others = Object.fromEntries(rules.filter(r => r.x.ok && r.ctor === undefined).map(r => [r.entry ?? r.x.model?.name ?? '', r.x]));
513
595
  const cfg = configFor(t.lang === 'go' || t.lang === 'rust' || fs.statSync(t.at).isDirectory() ? t.at : path.dirname(t.at));
514
- const baseCtx = { ms: o.ms, clock: unit === 's' ? 1 : unit === 'ms' ? 1000 : undefined, others, cites, cert: o.cert, file: path.relative(proc.cwd(), t.at) || t.at, ...(cfg.all.calendar ? { calendar: cfg.all.calendar } : {}) };
596
+ const baseCtx = { ms: o.ms, ...(o.work === undefined ? {} : { work: o.work }), watchdogMs: o.watchdogMs, clock: unit === 's' ? 1 : unit === 'ms' ? 1000 : undefined, others, cites, cert: o.cert, file: path.relative(proc.cwd(), t.at) || t.at, ...(cfg.all.calendar ? { calendar: cfg.all.calendar } : {}) };
515
597
  for (const [initializerIndex, { entry, ctor, x: x0 }] of rules.entries()) {
516
598
  // Different initial states must never overwrite one another's certificates.
517
599
  const ctx = ctor !== undefined && baseCtx.cert ? { ...baseCtx, cert: path.join(baseCtx.cert, `initializer-${initializerIndex}`) } : baseCtx;
@@ -535,11 +617,8 @@ export async function checkTarget(t, o) {
535
617
  continue;
536
618
  }
537
619
  // (an Effect service's primitives: the lemmas of their use proven first, each proven one beside every law)
538
- if (x.lemmas?.length) {
539
- const { withLemmas } = await import("./effect.js"), w = withLemmas(x, { ms: Math.max(o.ms, 30_000) });
540
- x = w.x;
541
- r.notes = [...r.notes, ...w.proven.map(n => `lemma proven, beside every law: ${n}`), ...w.unproven.map(n => `lemma not proven (left out): ${n}`)];
542
- }
620
+ if (x.lemmas?.length)
621
+ x = yield { lemmas: x, ms: Math.max(o.ms, 30_000), work: o.work, watchdogMs: o.watchdogMs, output: r };
543
622
  const ev = x.evidence;
544
623
  if (ev)
545
624
  r.checked = `checked against ${'probes' in ev ? `the code: ${ev.requests} requests from the start, ${ev.fromStates} from drawn states, ${ev.probes.steps} from the prover's witnesses` : `XState's own actor: ${ev.events} events`}${ev.coverage.arms ? `, ${ev.coverage.hit} of ${ev.coverage.arms} branch arms` : ''}${'startsOutside' in ev && ev.startsOutside ? `; ${ev.startsOutside} starts whose constructor passes 2^53 - 1 left out (outside the rule's numbers: the claim is for starts within them)` : ''}`;
@@ -600,7 +679,7 @@ export async function checkTarget(t, o) {
600
679
  const order = [...stated.keys()].sort((a, b) => rank(stated[a]) - rank(stated[b]));
601
680
  // (from any state, the laws about states as one inductive set: the largest the stated ones make, each law the
602
681
  // kernel's step breaks taken out in turn (Houdini), the others proven together; one taken out is judged alone)
603
- const inductive = from && x.rule && !sys ? houdini(x, stated.filter(m => twice(m).length === 1 && kindOf(m) === 'law'), o.ms, ctx) : undefined;
682
+ const inductive = from && x.rule && !sys ? houdini(x, stated.filter(m => twice(m).length === 1 && kindOf(m) === 'law'), o.ms, ctx, o.work, o.watchdogMs) : undefined;
604
683
  const outsOf = [];
605
684
  for (const i of order) {
606
685
  const l = stated[i];
@@ -611,11 +690,11 @@ export async function checkTarget(t, o) {
611
690
  if (o.security) {
612
691
  // Deliberately separate from accepted policy and from heuristic proposals that hide broken guesses.
613
692
  // Do not pass previously proven candidates as hypotheses; use the same environment/replay as stated laws.
614
- const candidates = securityTemplates(x), until = Date.now() + o.ms;
615
- r.security = candidates.map(l => ({ ...(Date.now() >= until
693
+ const candidates = securityTemplates(x), until = cliNow() + o.ms;
694
+ r.security = candidates.map(l => ({ ...(cliNow() >= until
616
695
  ? { name: l.name, expr: l.expr, verdict: 'unknown', why: 'security proposal budget exhausted', ms: 0 }
617
- : sys ? proveInEnv(x, l, Math.max(1, Math.min(2000, until - Date.now())), [], { ...ctx, sys, entry: name, cert: undefined })
618
- : prove(x, l, Math.max(1, Math.min(2000, until - Date.now())), [], { ...ctx, entry: name, cert: undefined })),
696
+ : sys ? proveInEnv(x, l, Math.max(1, Math.min(2000, until - cliNow())), [], { ...ctx, sys, entry: name, cert: undefined })
697
+ : prove(x, l, Math.max(1, Math.min(2000, until - cliNow())), [], { ...ctx, entry: name, cert: undefined })),
619
698
  securityKind: l.securityKind, review: l.review,
620
699
  where: `${l.method ? `above ${l.method}: ` : ''}${COMMENT[t.lang]} gdp: law ${l.name}: ${l.expr}` }));
621
700
  r.notes.push('security candidates require policy review; arbitrary requests in arbitrary order, values within the extracted types; bind identity/roles to authentication, not caller claims');
@@ -644,7 +723,7 @@ export async function checkTarget(t, o) {
644
723
  const CLOCK = { python: 's', elixir: 's', rust: 's', ts: 'ms', java: 'ms', kotlin: 'ms' };
645
724
  // The largest set of these laws that is inductive from every state they allow together: each law whose step the
646
725
  // kernel breaks taken out, the rest tried again.
647
- function houdini(x, ls, ms, opts) {
726
+ function houdini(x, ls, ms, opts, work, watchdogMs) {
648
727
  let set = ls.flatMap(l => { try {
649
728
  const b = buildLaw(x, l, opts);
650
729
  return b.kind === 'law' ? [{ l, law: b.law }] : [];
@@ -655,7 +734,7 @@ function houdini(x, ls, ms, opts) {
655
734
  for (let i = 0; i <= ls.length && set.length; i++) {
656
735
  let v;
657
736
  try {
658
- v = proveRule(x.rule, [...(x.invariants ?? []), ...set.map(s => s.law)], { search: { ms }, from: 'any' });
737
+ v = proveRule(x.rule, [...(x.invariants ?? []), ...set.map(s => s.law)], { search: work === undefined ? { ms } : { work }, from: 'any', watchdogMs });
659
738
  }
660
739
  catch {
661
740
  return new Set();
@@ -683,13 +762,15 @@ function ruleFor(x, expr) {
683
762
  const ks = [...expr.matchAll(/(?:\/\/|%)\s*(\d+)/g)].map(m => Number(m[1])).filter(k => k >= 1);
684
763
  return ks.length ? { ...x, rule: r.withDivisors(...ks) } : x;
685
764
  }
686
- function prove(x0, l, ms, proven, ctx) {
765
+ function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
687
766
  const x = ruleFor(x0, l.expr);
688
- const t0 = Date.now(), cites = ctx?.cites.filter(c => c.law === l.name).map(c => c.text) ?? [];
767
+ const t0 = cliNow(), cites = ctx?.cites.filter(c => c.law === l.name).map(c => c.text) ?? [];
689
768
  const base = { name: l.name, expr: l.expr, ...(l.where ? { where: l.where } : {}), ...(cites.length ? { cites } : {}) };
690
- const inv = x.invariants ?? [], search = { search: { ms }, ...(ctx?.from ? { from: ctx.from } : {}) };
769
+ const inv = x.invariants ?? [], search = { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs, ...(ctx?.from ? { from: ctx.from } : {}) };
691
770
  // (whenever <from>, later <to>: proven with the rule's invariants and the laws proven so far, each helpful request fair)
692
771
  if (isLeadsTo(l.expr)) {
772
+ if (work !== undefined || ctx?.watchdogMs !== undefined)
773
+ return { ...base, kind: 'leads to', verdict: 'unknown', why: `explicit ${work !== undefined ? 'work budget' : 'watchdog'} is not supported for leads-to checks`, ms: 0 };
693
774
  let lt;
694
775
  try {
695
776
  lt = buildLeadsTo(x, l, { clock: ctx?.clock });
@@ -704,9 +785,9 @@ function prove(x0, l, ms, proven, ctx) {
704
785
  v = proveLeadsTo(x.rule, [...inv, ...proven], lt, { ms });
705
786
  }
706
787
  catch (e) {
707
- return { ...base, kind: 'leads to', verdict: 'unknown', why: e.message, ms: Date.now() - t0 };
788
+ return { ...base, kind: 'leads to', verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
708
789
  }
709
- return { ...base, ...translationOf(v), kind: 'leads to', verdict: v.proven && v.checked ? 'proven' : 'unknown', ...(v.proven && v.checked ? {} : { why: [v.goal, v.stuck, v.why].filter(Boolean).join('; ') || 'not proven' }), ms: Date.now() - t0 };
790
+ return { ...base, ...translationOf(v), ...searchOf(v), kind: 'leads to', verdict: v.proven && v.checked ? 'proven' : 'unknown', ...(v.proven && v.checked ? {} : { why: whyOf(v, [v.goal, v.stuck, v.why].filter(Boolean).join('; ') || 'not proven') }), ms: cliNow() - t0 };
710
791
  }
711
792
  let b, two;
712
793
  // (a law that can't be built is not read, with why: never the whole check aborted)
@@ -720,20 +801,22 @@ function prove(x0, l, ms, proven, ctx) {
720
801
  return { ...base, verdict: 'not read', why: e.message, ms: 0 };
721
802
  }
722
803
  const kind = two ? 'two runs' : b.kind;
804
+ if (two && (work !== undefined || ctx?.watchdogMs !== undefined))
805
+ return { ...base, kind, verdict: 'unknown', why: `explicit ${work !== undefined ? 'work budget' : 'watchdog'} is not supported for two-run checks: helper preflight is not yet ${work !== undefined ? 'work' : 'watchdog'}-scoped`, ms: 0 };
723
806
  let v;
724
807
  // (from any state, a law about states outside the inductive set: false from the start (a run), or true there and
725
808
  // needing a law beside it to hold from every state the laws allow)
726
809
  if (ctx?.from && ctx.inductive && b?.kind === 'law' && !ctx.inductive.has(l.name)) {
727
810
  let r;
728
811
  try {
729
- r = proveRule(x.rule, [...inv, b.law], { search: { ms } });
812
+ r = proveRule(x.rule, [...inv, b.law], { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs });
730
813
  }
731
814
  catch (e) {
732
- return { ...base, kind: 'law', verdict: 'unknown', why: e.message, ms: Date.now() - t0 };
815
+ return { ...base, kind: 'law', verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
733
816
  }
734
- if (r.run && r.translation !== 'unchecked')
735
- return { ...base, ...translationOf(r), kind: 'law', verdict: 'broken', run: runOf(x, r.run), ms: Date.now() - t0 };
736
- return { ...base, ...translationOf(r), kind: 'law', verdict: 'unknown', why: r.proven && r.checked ? `true in every state a run from the start reaches, not inductive from every state the laws allow (from = "any"): state the law it needs beside it${r.found?.laws?.length ? `: ${r.found.laws.map(f => f.text).join('; ')}` : ''}` : r.why ?? r.stuck ?? 'not proven', ...(r.found?.laws?.length ? { found: r.found.laws.map(f => f.text) } : {}), ms: Date.now() - t0 };
817
+ if (r.run && r.translation !== 'unchecked' && r.translation !== 'error')
818
+ return { ...base, ...translationOf(r), ...searchOf(r), kind: 'law', verdict: 'broken', run: runOf(x, r.run), ms: cliNow() - t0 };
819
+ return { ...base, ...translationOf(r), ...searchOf(r), kind: 'law', verdict: r.translation === 'error' ? 'not read' : 'unknown', why: r.proven && r.checked ? `true in every state a run from the start reaches, not inductive from every state the laws allow (from = "any"): state the law it needs beside it${r.found?.laws?.length ? `: ${r.found.laws.map(f => f.text).join('; ')}` : ''}` : whyOf(r, r.why ?? r.stuck ?? 'not proven'), ...(r.found?.laws?.length ? { found: r.found.laws.map(f => f.text) } : {}), ms: cliNow() - t0 };
737
820
  }
738
821
  // (from any state: a law about states proven with the others stated beside it, as one inductive set)
739
822
  const beside = () => (ctx?.together ?? []).filter(m => m.name !== l.name).flatMap(m => { try {
@@ -747,13 +830,13 @@ function prove(x0, l, ms, proven, ctx) {
747
830
  v = two ? proveTwoRuns(two, { ...search, invariants: [two.sides[0] === x.rule ? inv : (ctx?.others && Object.values(ctx.others).find(o => o.rule === two.sides[0])?.invariants) ?? [], inv] }) : b.kind === 'law' ? proveRule(x.rule, [...inv, ...(ctx?.from ? beside() : []), b.law], search) : proveSteps(x.rule, [...inv, ...proven], [b.law], search);
748
831
  }
749
832
  catch (e) {
750
- return { ...base, kind, verdict: 'unknown', why: e.message, ms: Date.now() - t0 };
833
+ return { ...base, kind, verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
751
834
  }
752
835
  // (from any state: a step that breaks the law from a state the laws allow refutes it, reachable or not; the run that
753
836
  // reaches one from the start, where the search from the start finds it, is shown with it)
754
- if (ctx?.from && !v.proven && !v.run && v.stuck === 'sat' && v.witness && b) {
837
+ if (ctx?.from && !v.proven && !v.run && !v.stopped && v.stuck === 'sat' && v.witness && b) {
755
838
  try {
756
- const r = b.kind === 'law' ? proveRule(x.rule, [...inv, b.law], { search: { ms } }) : proveSteps(x.rule, [...inv, ...proven], [b.law], { search: { ms } });
839
+ const r = b.kind === 'law' ? proveRule(x.rule, [...inv, b.law], { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs }) : proveSteps(x.rule, [...inv, ...proven], [b.law], { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs });
757
840
  if (r.run)
758
841
  v = { ...v, run: r.run };
759
842
  }
@@ -761,7 +844,7 @@ function prove(x0, l, ms, proven, ctx) {
761
844
  if (!v.run)
762
845
  v = { ...v, why: `broken from a state the laws allow (from = "any"), no run from the start found reaching it` };
763
846
  }
764
- const brokenAt = !!(ctx?.from && !v.proven && !v.run && v.stuck === 'sat' && v.witness);
847
+ const brokenAt = !!(ctx?.from && !v.proven && !v.run && !searchOf(v).stopped && v.stuck === 'sat' && v.witness);
765
848
  let verdict = v.proven && v.checked && !(ctx?.from && v.assumes) ? 'proven' : v.run || brokenAt ? 'broken' : 'unknown', replayed;
766
849
  if (v.translation === 'unchecked')
767
850
  verdict = 'unknown';
@@ -796,13 +879,14 @@ function prove(x0, l, ms, proven, ctx) {
796
879
  fs.writeFileSync(cert, JSON.stringify(doc));
797
880
  }
798
881
  }
799
- return { ...base, ...translationOf(v), kind, verdict, ...(ctx?.from && verdict === 'proven' ? { from: 'any' } : {}), ...(replayed ? { replayed } : {}), ...(v.run && verdict === 'broken' ? { run: two ? pairRunOf(x, v.run, two) : runOf(x, v.run) } : {}), ...(verdict === 'unknown' || verdict === 'not read' || (verdict === 'broken' && !v.run) ? { why: [v.why ?? v.stuck ?? 'not proven', ...(at.length ? [`a state the laws allow where a step breaks it, no run from the start found reaching it: ${at.join(', ')}`] : [])].join('; ') } : {}),
800
- ...(v.run && !two ? { assumes: assumedOf(x, v.run) } : {}), ...(found?.length ? { found } : {}), ...(cert ? { cert } : {}), ms: Date.now() - t0 };
882
+ return { ...base, ...translationOf(v), ...searchOf(v), kind, verdict, ...(ctx?.from && verdict === 'proven' ? { from: 'any' } : {}), ...(replayed ? { replayed } : {}), ...(v.run && verdict === 'broken' ? { run: two ? pairRunOf(x, v.run, two) : runOf(x, v.run) } : {}), ...(verdict === 'unknown' || verdict === 'not read' || (verdict === 'broken' && !v.run) ? { why: whyOf(v, [v.why ?? v.stuck ?? 'not proven', ...(at.length ? [`a state the laws allow where a step breaks it, no run from the start found reaching it: ${at.join(', ')}`] : [])].join('; ')) } : {}),
883
+ ...(v.run && !two ? { assumes: assumedOf(x, v.run) } : {}), ...(found?.length ? { found } : {}), ...(cert ? { cert } : {}), ms: cliNow() - t0 };
801
884
  }
802
885
  // A law of a rule in its environment (core/system.ts's inEnv): built on the rule as the code's names read it, then
803
886
  // lifted to every call at once; proven of the system, a run shown as the calls' steps.
804
887
  function proveInEnv(x, l, ms, proven, ctx) {
805
- const t0 = Date.now(), sys = ctx.sys, base = { name: l.name, expr: l.expr, ...(l.where ? { where: l.where } : {}) };
888
+ const work = ctx.work;
889
+ const t0 = cliNow(), sys = ctx.sys, base = { name: l.name, expr: l.expr, ...(l.where ? { where: l.where } : {}) };
806
890
  if (isLeadsTo(l.expr) || isTwoRuns(l.expr))
807
891
  return { ...base, verdict: 'not read', why: `a ${isLeadsTo(l.expr) ? 'leads-to' : 'two-run'} law is not lifted to the environment (state it of the rule with no env)`, ms: 0 };
808
892
  // (at most one call between a and b: a flow's mutual exclusion, its leases running out where their keys expire)
@@ -819,18 +903,18 @@ function proveInEnv(x, l, ms, proven, ctx) {
819
903
  try {
820
904
  if (b.kind === 'law') {
821
905
  law = bw ? b.law : sys.law(b.law);
822
- v = proveRule(sys.rule, [...inv, law], { search: { ms } });
906
+ v = proveRule(sys.rule, [...inv, law], { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs });
823
907
  }
824
908
  else {
825
909
  law = sys.step(b.law);
826
- v = proveSteps(sys.rule, [...inv, ...proven], [law], { search: { ms } });
910
+ v = proveSteps(sys.rule, [...inv, ...proven], [law], { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs });
827
911
  }
828
912
  }
829
913
  catch (e) {
830
- return { ...base, kind: b.kind, verdict: 'unknown', why: e.message, ms: Date.now() - t0 };
914
+ return { ...base, kind: b.kind, verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
831
915
  }
832
916
  // (not proven and no run: calls contending with one request, a run the search's own draws seldom make)
833
- if (!(v.proven && v.checked) && !v.run) {
917
+ if (work === undefined && !v.stopped && !(v.proven && v.checked) && !v.run) {
834
918
  const run = contend(sys, law, { ms: Math.min(ms, 10_000) });
835
919
  if (run)
836
920
  v = { ...v, run: run };
@@ -839,7 +923,7 @@ function proveInEnv(x, l, ms, proven, ctx) {
839
923
  if (verdict === 'proven' && b.kind === 'law')
840
924
  proven.push(law);
841
925
  const found = v.found?.laws?.map(f => f.text);
842
- return { ...base, ...translationOf(v), kind: b.kind, verdict, ...(v.run && verdict === 'broken' ? { run: sysRunOf(x, sys, shrinkRun(sys.rule, law, v.run)) } : {}), ...(verdict === 'unknown' || verdict === 'not read' ? { why: v.why ?? v.stuck ?? 'not proven' } : {}), ...(found?.length ? { found } : {}), ms: Date.now() - t0 };
926
+ return { ...base, ...translationOf(v), ...searchOf(v), kind: b.kind, verdict, ...(v.run && verdict === 'broken' ? { run: sysRunOf(x, sys, shrinkRun(sys.rule, law, v.run)) } : {}), ...(verdict === 'unknown' || verdict === 'not read' ? { why: whyOf(v, v.why ?? v.stuck ?? 'not proven') } : {}), ...(found?.length ? { found } : {}), ms: cliNow() - t0 };
843
927
  }
844
928
  // A run of the system as each call's steps: a call begins with its request, reads, commits; a store's key expires.
845
929
  function sysRunOf(x, sys, run) {
@@ -1007,11 +1091,11 @@ function propose(x, lang, o, proven, stated) {
1007
1091
  add(`${codeOf(v)} never goes down`, `${codeOf(v)} >= old(${codeOf(v)})`);
1008
1092
  add(`${codeOf(v)} never goes up`, `${codeOf(v)} <= old(${codeOf(v)})`);
1009
1093
  }
1010
- const shown = [], until = Date.now() + Math.max(5000, o.ms * 2);
1094
+ const shown = [], until = cliNow() + Math.max(5000, o.ms * 2);
1011
1095
  let broken = 0;
1012
1096
  const fixed = new Set();
1013
- for (const c of cands.slice(0, 40)) {
1014
- if (Date.now() > until)
1097
+ for (const c of cands.slice(0, syncControl ? Math.min(40, syncControl.candidates) : 40)) {
1098
+ if (cliNow() > until)
1015
1099
  break;
1016
1100
  const v = /^(.+) never (?:changes|goes (?:down|up))$/.exec(c.name)?.[1];
1017
1101
  if (v && fixed.has(v))
@@ -1072,11 +1156,23 @@ function printRule(r, o) {
1072
1156
  out(` proven with what the search found: ${l.found.join('; ')}`);
1073
1157
  if (l.why && l.verdict !== 'proven')
1074
1158
  out(` ${l.why}`);
1159
+ if (l.stopped && l.termination) {
1160
+ out(` stopped: true; ${terminationWhy(l.termination)}`);
1161
+ if (l.context)
1162
+ out(` search context (not a reachable run): ${JSON.stringify(l.context)}`);
1163
+ }
1075
1164
  if (l.translationWitness)
1076
1165
  out(` translation witness: ${JSON.stringify(l.translationWitness)}`);
1077
1166
  if (proposed)
1078
1167
  out(` ${l.where}`);
1079
1168
  };
1169
+ for (const a of r.supportAttempts ?? []) {
1170
+ out(` optional support ${a.name}: ${a.proven && a.checked ? 'proven' : 'not proven'}${a.stopped && a.termination ? `; stopped: true; ${terminationWhy(a.termination)}` : ''}`);
1171
+ if (a.why || a.failure)
1172
+ out(` ${a.why ?? `${a.failure.name}: ${a.failure.message}`}`);
1173
+ if (a.context)
1174
+ out(` context: ${JSON.stringify(a.context)}`);
1175
+ }
1080
1176
  if (r.laws.length) {
1081
1177
  out(' laws stated in the code:');
1082
1178
  for (const l of r.laws)
@@ -1101,7 +1197,7 @@ function printRule(r, o) {
1101
1197
  out();
1102
1198
  }
1103
1199
  const label = (n) => (n.role === 'answer' ? `${n.code.split('.').pop()}(...)` : n.role === 'input' && n.method ? `${n.method}(${n.code})` : n.role === 'result' && n.method ? `${n.method}() result` : n.code);
1104
- const USAGE = `gdp-wired check <file|dir>... [--entry X] [--mode standalone] [--methods a,b] [--failures kept] [--on-error discard] [--json] [--ms 10000] [--no-propose] [--clock s|ms] [--cert <dir>] [--from any] [--require-review] [--security]
1200
+ const USAGE = `gdp-wired check <file|dir>... [--entry X] [--mode standalone] [--methods a,b] [--failures kept] [--on-error discard] [--json] [--ms 10000 | --work UNITS] [--watchdog-ms MS] [--no-propose] [--clock s|ms] [--cert <dir>] [--from any] [--require-review] [--security]
1105
1201
  gdp-wired lift <capsule> <source.json> [--out DIR] [--emit-only] [--sha256 HASH] [--json]
1106
1202
  gdp-wired mutate <config.json> [--json]
1107
1203
  gdp-wired draft <file> --clause <text> | --clause-file <file> --cite <ref> [--llm <command> | --answer <file>] [--by <who>]
@@ -1120,6 +1216,15 @@ not authenticated identities. State the intended policy with gdp: law comments;
1120
1216
  // Every target's rules and their laws, and the exit code (1: a stated law broken; 2: one not checked).
1121
1217
  export async function check(targets, given = {}, each) {
1122
1218
  const o = { ms: 10_000, propose: true, ...given }, all = [];
1219
+ validateWatchdog(o.watchdogMs);
1220
+ if (o.work !== undefined) {
1221
+ if (given.ms !== undefined)
1222
+ throw new RangeError('choose a work budget or a legacy ms budget, not both');
1223
+ if (!Number.isSafeInteger(o.work) || o.work < 0)
1224
+ throw new RangeError('work budget must be a nonnegative safe integer');
1225
+ if (o.propose || o.security)
1226
+ throw new RangeError('explicit work check requires propose: false and does not support security proposals');
1227
+ }
1123
1228
  for (const p of targets)
1124
1229
  for (const t of targetsOf(p)) {
1125
1230
  const rs = await checkTarget(t, o);
@@ -1142,7 +1247,7 @@ async function draft(target, o) {
1142
1247
  out('gdp-wired draft: --clause <text> or --clause-file <file>');
1143
1248
  return 2;
1144
1249
  }
1145
- const t = targetsOf(target)[0], rules = await rulesOf(t, { ...o, propose: false }, []), x = rules.find(r => r.x.ok)?.x;
1250
+ const t = targetsOf(target)[0], rules = await drivePipeline(rulesOf(t, { ...o, propose: false }, [])), x = rules.find(r => r.x.ok)?.x;
1146
1251
  if (!x) {
1147
1252
  out(`gdp-wired draft: no rule read from ${target}: ${rules[0]?.x.refusals[0]?.what ?? ''}`);
1148
1253
  return 2;
@@ -1182,7 +1287,8 @@ async function draft(target, o) {
1182
1287
  export async function main(argv) {
1183
1288
  if (argv[0] === 'lift')
1184
1289
  return (await import("./lift-cli.js")).liftMain(argv.slice(1));
1185
- const { cmd, targets, o } = args(argv);
1290
+ const { cmd, targets, o: given } = args(argv);
1291
+ const o = { ms: 10_000, propose: true, ...given };
1186
1292
  if (cmd === 'mutate' && targets.length === 1) {
1187
1293
  const { checkMutations } = await import("./mutate.js");
1188
1294
  const file = path.resolve(targets[0]), config = JSON.parse(fs.readFileSync(file, 'utf8'));
@@ -1197,7 +1303,7 @@ export async function main(argv) {
1197
1303
  return cmd === 'help' || cmd === '--help' || cmd === '-h' || !cmd ? 0 : 2;
1198
1304
  }
1199
1305
  tint = colors(proc.env, !!proc.stdout.isTTY, !!o.json);
1200
- const { rules: all, exit: code0 } = await check(targets, o, o.json ? undefined : r => printRule(r, o));
1306
+ const { rules: all, exit: code0 } = await check(targets, given, o.json ? undefined : r => printRule(r, o));
1201
1307
  const stated = all.flatMap(r => r.laws);
1202
1308
  const { reviewOf } = await import("./draft.js"), unreviewed = stated.filter(l => (l.cites ?? []).some(c => reviewOf(c) === 'unreviewed'));
1203
1309
  const code = code0 === 0 && o.requireReview && unreviewed.length ? 2 : code0;
@@ -1,3 +1,4 @@
1
+ import { type WorkAmount } from './work-amount.js';
1
2
  import { type Law } from './machine.js';
2
3
  import { type StepLaw, type Verdict, Rule } from './dsl.js';
3
4
  import { type Fold } from '../kernel/kernel.js';
@@ -12,7 +13,11 @@ export type Discovery = {
12
13
  rule: AnyRule;
13
14
  found: Record<string, Found>;
14
15
  };
15
- export declare function discover(r: AnyRule, laws: Law[], stepLaws?: StepLaw[], first?: Verdict): Discovery;
16
+ export type DiscoverOptions = {
17
+ work?: number | WorkAmount;
18
+ watchdogMs?: number;
19
+ };
20
+ export declare function discover(r: AnyRule, laws: Law[], stepLaws?: StepLaw[], first?: Verdict, opts?: DiscoverOptions): Discovery;
16
21
  type TreeFold = {
17
22
  fold: Fold;
18
23
  lemmas?: Law[];