gdp-wired 0.50.1 → 0.50.3
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/README.md +4 -2
- package/dist/core/cli.d.ts +12 -1
- package/dist/core/cli.js +64 -26
- package/dist/core/discover.d.ts +6 -1
- package/dist/core/discover.js +54 -7
- package/dist/core/dsl-deadline.d.ts +3 -0
- package/dist/core/dsl-deadline.js +26 -2
- package/dist/core/dsl.d.ts +3 -1
- package/dist/core/dsl.js +97 -32
- package/dist/core/effect.d.ts +12 -0
- package/dist/core/effect.js +26 -9
- package/dist/core/ex/harness.exs +171 -5
- package/dist/core/extract-c.js +64 -7
- package/dist/core/extract-check.d.ts +5 -1
- package/dist/core/extract-check.js +28 -10
- package/dist/core/extract-go-check.js +130 -3
- package/dist/core/extract-go.js +8 -2
- package/dist/core/extract-jvm.js +2 -2
- package/dist/core/extract-rs.js +51 -5
- package/dist/core/extract-step.js +49 -6
- package/dist/core/extract-swift.js +47 -3
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/infer.d.ts +8 -0
- package/dist/core/infer.js +133 -16
- package/dist/core/jvm/Harness.java +135 -3
- package/dist/core/jvm/Rt.java +66 -4
- package/dist/core/laws.d.ts +4 -0
- package/dist/core/laws.js +59 -10
- package/dist/core/native-law.d.ts +3 -1
- package/dist/core/native-law.js +126 -14
- package/dist/core/native-observations.d.ts +20 -0
- package/dist/core/native-observations.js +41 -0
- package/dist/core/native-wire.d.ts +2 -0
- package/dist/core/native-wire.js +99 -0
- package/dist/core/py/harness.py +53 -2
- package/dist/core/rb/harness.rb +178 -9
- package/dist/core/search-termination.d.ts +35 -0
- package/dist/core/search-termination.js +13 -0
- package/dist/core/search-watchdog.d.ts +8 -0
- package/dist/core/search-watchdog.js +34 -0
- package/dist/core/source-check.d.ts +5 -0
- package/dist/core/source-check.js +21 -0
- package/dist/core/swift/Harness.swift +65 -4
- package/dist/core/swift/Main.swift +27 -4
- package/dist/core/wall.d.ts +3 -1
- package/dist/core/wall.js +7 -4
- package/dist/core/work-refusal.d.ts +3 -0
- package/dist/core/work-refusal.js +8 -0
- package/dist/kernel/prove.d.ts +2 -0
- package/dist/kernel/prove.js +13 -5
- package/dist/kernel/reader.js +5 -1
- package/dist/lean-kernel/axiom-audit.js +5 -2
- package/dist/lean-kernel/emit.d.ts +1 -0
- package/dist/lean-kernel/emit.js +22 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -249,8 +249,10 @@ All of these are proven automatically, and each proof is also a Lean theorem:
|
|
|
249
249
|
- **What nobody stated, looked for when the prover alone stops**: where `proveRule` or `proveSteps` doesn't prove the laws
|
|
250
250
|
and no run breaks them, it looks for lemmas about the rule's recurrences and lists (`discover`), lemmas about the
|
|
251
251
|
functions it knows by their facts (`cycleLemmas`, each proven by a cyclic proof) and then invariants (`inferLaws`),
|
|
252
|
-
|
|
253
|
-
proved them, as laws and lemmas with the source to paste.
|
|
252
|
+
under a configurable search allowance (`{search: {ms: 10000}}` by default; `{search: false}`, the prover alone);
|
|
253
|
+
the verdict's `found` holds what proved them, as laws and lemmas with the source to paste.
|
|
254
|
+
[Explicit counted work and stop causes](docs/search-budgets.md) separate the search allowance from an optional
|
|
255
|
+
real-time safety watchdog; legacy `ms` is not a promise of machine-independent completion. Each invariant found holds in the states reachable from the
|
|
254
256
|
start, so a proof that needs one holds there and the verdict says so (`assumes: {states: 'reachable', laws}`). Code that
|
|
255
257
|
steps the rule from states it is handed proves with `{from: 'any'}`: every step law then holds from every state the
|
|
256
258
|
laws allow, reachable or not, and the search never adds an invariant.
|
package/dist/core/cli.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Extraction, Name } from './extract.js';
|
|
|
3
3
|
import { type SecurityCandidate } from './security.js';
|
|
4
4
|
import { type Verdict } from './dsl.js';
|
|
5
5
|
import type { TranslationFields } from './source-check.js';
|
|
6
|
+
import { type SearchTerminationFields } from './search-termination.js';
|
|
6
7
|
import { type LawText } from './laws.js';
|
|
7
8
|
export declare const colors: (env: Record<string, string | undefined>, tty: boolean, json?: boolean) => boolean;
|
|
8
9
|
export type Opts = {
|
|
@@ -13,6 +14,8 @@ export type Opts = {
|
|
|
13
14
|
onError?: 'refuse' | 'discard';
|
|
14
15
|
json?: boolean;
|
|
15
16
|
ms: number;
|
|
17
|
+
work?: number;
|
|
18
|
+
watchdogMs?: number;
|
|
16
19
|
propose: boolean;
|
|
17
20
|
root?: string;
|
|
18
21
|
python?: string;
|
|
@@ -35,7 +38,7 @@ type Config = {
|
|
|
35
38
|
};
|
|
36
39
|
export declare function configFor(from: string): Config;
|
|
37
40
|
export declare function toml(text: string): Record<string, unknown>;
|
|
38
|
-
type LawOut = Omit<TranslationFields, 'translationWitness'> & {
|
|
41
|
+
type LawOut = SearchTerminationFields & Omit<TranslationFields, 'translationWitness'> & {
|
|
39
42
|
translationWitness?: unknown;
|
|
40
43
|
name: string;
|
|
41
44
|
expr: string;
|
|
@@ -52,7 +55,15 @@ type LawOut = Omit<TranslationFields, 'translationWitness'> & {
|
|
|
52
55
|
cert?: string;
|
|
53
56
|
ms: number;
|
|
54
57
|
};
|
|
58
|
+
type SupportAttempt = SearchTerminationFields & Pick<Partial<Verdict>, 'proven' | 'checked' | 'why' | 'translation' | 'kernelProven'> & {
|
|
59
|
+
name: string;
|
|
60
|
+
failure?: {
|
|
61
|
+
name: string;
|
|
62
|
+
message: string;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
55
65
|
export type RuleOut = {
|
|
66
|
+
supportAttempts?: SupportAttempt[];
|
|
56
67
|
file: string;
|
|
57
68
|
lang: string;
|
|
58
69
|
entry?: string;
|
package/dist/core/cli.js
CHANGED
|
@@ -10,6 +10,8 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
10
10
|
import { fiberRun } from "./fiber-run.js";
|
|
11
11
|
import { securityTemplates } from "./security.js";
|
|
12
12
|
import { proveLeadsTo, proveRule, proveSteps } from "./dsl.js";
|
|
13
|
+
import { terminationWhy } from "./search-termination.js";
|
|
14
|
+
import { validateWatchdog } from "./search-watchdog.js";
|
|
13
15
|
import { sourceDiagnostic } from "./source-diagnostic.js";
|
|
14
16
|
import { LawError, buildLaw, buildLeadsTo, buildTwoRuns, citesIn, isLeadsTo, isTwoRuns, lawsIn, namesWithClock } from "./laws.js";
|
|
15
17
|
import { certify, proveTwoRuns } from "./relational.js";
|
|
@@ -25,7 +27,7 @@ const SGR = { green: 32, red: 31, yellow: 33, dim: 2 };
|
|
|
25
27
|
const paint = (c, s) => (tint && s !== '' ? `\x1b[${SGR[c]}m${s}\x1b[0m` : String(s));
|
|
26
28
|
const VERDICT = { proven: 'green', broken: 'red', unknown: 'yellow', 'not read': 'yellow' };
|
|
27
29
|
function args(argv) {
|
|
28
|
-
const o = {
|
|
30
|
+
const o = { propose: true }, targets = [];
|
|
29
31
|
let cmd = '';
|
|
30
32
|
for (let i = 0; i < argv.length; i++) {
|
|
31
33
|
const a = argv[i];
|
|
@@ -40,7 +42,7 @@ function args(argv) {
|
|
|
40
42
|
else if (a.startsWith('--')) {
|
|
41
43
|
const [k, inline] = a.slice(2).split('='), v = inline ?? argv[++i] ?? '';
|
|
42
44
|
const key = k.replace(/-(\w)/g, (_, c) => c.toUpperCase());
|
|
43
|
-
o[key] = key === 'methods' ? v.split(',') : key === 'ms' ? Number(v) : v;
|
|
45
|
+
o[key] = key === 'methods' ? v.split(',') : key === 'ms' || key === 'work' || key === 'watchdogMs' ? Number(v) : v;
|
|
44
46
|
}
|
|
45
47
|
else if (!cmd)
|
|
46
48
|
cmd = a;
|
|
@@ -284,6 +286,13 @@ const translationOf = (v) => ({
|
|
|
284
286
|
...(v.kernelProven !== undefined ? { kernelProven: v.kernelProven } : {}),
|
|
285
287
|
...(v.translationWitness ? { translationWitness: sourceDiagnostic(v.translationWitness) } : {}),
|
|
286
288
|
});
|
|
289
|
+
// Only structured provenance can explain cancellation. A semantic unknown whose
|
|
290
|
+
// text happens to say "time" or "work" is not a stopped search. Native refusal
|
|
291
|
+
// remains the primary diagnostic, with any search stop carried separately.
|
|
292
|
+
const searchOf = (v) => v.stopped && v.termination && !(v.proven && v.checked) && !v.run
|
|
293
|
+
? { stopped: true, termination: v.termination, ...(v.context ? { context: v.context } : {}) } : {};
|
|
294
|
+
const whyOf = (v, semantic) => searchOf(v).termination && v.translation !== 'unchecked' && v.translation !== 'error'
|
|
295
|
+
? terminationWhy(v.termination) : semantic;
|
|
287
296
|
// Each initializer is a separate scope, with its own original-code replay and laws. Never choose one
|
|
288
297
|
// overload on the caller's behalf or let a successful variant hide another variant's refusal.
|
|
289
298
|
async function expandInitializers(t, o, laws, rows) {
|
|
@@ -511,7 +520,7 @@ export async function checkTarget(t, o) {
|
|
|
511
520
|
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
521
|
const others = Object.fromEntries(rules.filter(r => r.x.ok && r.ctor === undefined).map(r => [r.entry ?? r.x.model?.name ?? '', r.x]));
|
|
513
522
|
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 } : {}) };
|
|
523
|
+
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
524
|
for (const [initializerIndex, { entry, ctor, x: x0 }] of rules.entries()) {
|
|
516
525
|
// Different initial states must never overwrite one another's certificates.
|
|
517
526
|
const ctx = ctor !== undefined && baseCtx.cert ? { ...baseCtx, cert: path.join(baseCtx.cert, `initializer-${initializerIndex}`) } : baseCtx;
|
|
@@ -536,8 +545,9 @@ export async function checkTarget(t, o) {
|
|
|
536
545
|
}
|
|
537
546
|
// (an Effect service's primitives: the lemmas of their use proven first, each proven one beside every law)
|
|
538
547
|
if (x.lemmas?.length) {
|
|
539
|
-
const { withLemmas } = await import("./effect.js"), w = withLemmas(x, { ms: Math.max(o.ms, 30_000) });
|
|
548
|
+
const { withLemmas } = await import("./effect.js"), w = withLemmas(x, { ...(o.work === undefined ? { ms: Math.max(o.ms, 30_000) } : { work: o.work }), watchdogMs: o.watchdogMs });
|
|
540
549
|
x = w.x;
|
|
550
|
+
r.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 } : {}) }));
|
|
541
551
|
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
552
|
}
|
|
543
553
|
const ev = x.evidence;
|
|
@@ -600,7 +610,7 @@ export async function checkTarget(t, o) {
|
|
|
600
610
|
const order = [...stated.keys()].sort((a, b) => rank(stated[a]) - rank(stated[b]));
|
|
601
611
|
// (from any state, the laws about states as one inductive set: the largest the stated ones make, each law the
|
|
602
612
|
// 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;
|
|
613
|
+
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
614
|
const outsOf = [];
|
|
605
615
|
for (const i of order) {
|
|
606
616
|
const l = stated[i];
|
|
@@ -644,7 +654,7 @@ export async function checkTarget(t, o) {
|
|
|
644
654
|
const CLOCK = { python: 's', elixir: 's', rust: 's', ts: 'ms', java: 'ms', kotlin: 'ms' };
|
|
645
655
|
// The largest set of these laws that is inductive from every state they allow together: each law whose step the
|
|
646
656
|
// kernel breaks taken out, the rest tried again.
|
|
647
|
-
function houdini(x, ls, ms, opts) {
|
|
657
|
+
function houdini(x, ls, ms, opts, work, watchdogMs) {
|
|
648
658
|
let set = ls.flatMap(l => { try {
|
|
649
659
|
const b = buildLaw(x, l, opts);
|
|
650
660
|
return b.kind === 'law' ? [{ l, law: b.law }] : [];
|
|
@@ -655,7 +665,7 @@ function houdini(x, ls, ms, opts) {
|
|
|
655
665
|
for (let i = 0; i <= ls.length && set.length; i++) {
|
|
656
666
|
let v;
|
|
657
667
|
try {
|
|
658
|
-
v = proveRule(x.rule, [...(x.invariants ?? []), ...set.map(s => s.law)], { search: { ms }, from: 'any' });
|
|
668
|
+
v = proveRule(x.rule, [...(x.invariants ?? []), ...set.map(s => s.law)], { search: work === undefined ? { ms } : { work }, from: 'any', watchdogMs });
|
|
659
669
|
}
|
|
660
670
|
catch {
|
|
661
671
|
return new Set();
|
|
@@ -683,13 +693,15 @@ function ruleFor(x, expr) {
|
|
|
683
693
|
const ks = [...expr.matchAll(/(?:\/\/|%)\s*(\d+)/g)].map(m => Number(m[1])).filter(k => k >= 1);
|
|
684
694
|
return ks.length ? { ...x, rule: r.withDivisors(...ks) } : x;
|
|
685
695
|
}
|
|
686
|
-
function prove(x0, l, ms, proven, ctx) {
|
|
696
|
+
function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
687
697
|
const x = ruleFor(x0, l.expr);
|
|
688
698
|
const t0 = Date.now(), cites = ctx?.cites.filter(c => c.law === l.name).map(c => c.text) ?? [];
|
|
689
699
|
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 } : {}) };
|
|
700
|
+
const inv = x.invariants ?? [], search = { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs, ...(ctx?.from ? { from: ctx.from } : {}) };
|
|
691
701
|
// (whenever <from>, later <to>: proven with the rule's invariants and the laws proven so far, each helpful request fair)
|
|
692
702
|
if (isLeadsTo(l.expr)) {
|
|
703
|
+
if (work !== undefined || ctx?.watchdogMs !== undefined)
|
|
704
|
+
return { ...base, kind: 'leads to', verdict: 'unknown', why: `explicit ${work !== undefined ? 'work budget' : 'watchdog'} is not supported for leads-to checks`, ms: 0 };
|
|
693
705
|
let lt;
|
|
694
706
|
try {
|
|
695
707
|
lt = buildLeadsTo(x, l, { clock: ctx?.clock });
|
|
@@ -706,7 +718,7 @@ function prove(x0, l, ms, proven, ctx) {
|
|
|
706
718
|
catch (e) {
|
|
707
719
|
return { ...base, kind: 'leads to', verdict: 'unknown', why: e.message, ms: Date.now() - t0 };
|
|
708
720
|
}
|
|
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 };
|
|
721
|
+
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: Date.now() - t0 };
|
|
710
722
|
}
|
|
711
723
|
let b, two;
|
|
712
724
|
// (a law that can't be built is not read, with why: never the whole check aborted)
|
|
@@ -720,20 +732,22 @@ function prove(x0, l, ms, proven, ctx) {
|
|
|
720
732
|
return { ...base, verdict: 'not read', why: e.message, ms: 0 };
|
|
721
733
|
}
|
|
722
734
|
const kind = two ? 'two runs' : b.kind;
|
|
735
|
+
if (two && (work !== undefined || ctx?.watchdogMs !== undefined))
|
|
736
|
+
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
737
|
let v;
|
|
724
738
|
// (from any state, a law about states outside the inductive set: false from the start (a run), or true there and
|
|
725
739
|
// needing a law beside it to hold from every state the laws allow)
|
|
726
740
|
if (ctx?.from && ctx.inductive && b?.kind === 'law' && !ctx.inductive.has(l.name)) {
|
|
727
741
|
let r;
|
|
728
742
|
try {
|
|
729
|
-
r = proveRule(x.rule, [...inv, b.law], { search: { ms } });
|
|
743
|
+
r = proveRule(x.rule, [...inv, b.law], { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs });
|
|
730
744
|
}
|
|
731
745
|
catch (e) {
|
|
732
746
|
return { ...base, kind: 'law', verdict: 'unknown', why: e.message, ms: Date.now() - t0 };
|
|
733
747
|
}
|
|
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 };
|
|
748
|
+
if (r.run && r.translation !== 'unchecked' && r.translation !== 'error')
|
|
749
|
+
return { ...base, ...translationOf(r), ...searchOf(r), kind: 'law', verdict: 'broken', run: runOf(x, r.run), ms: Date.now() - t0 };
|
|
750
|
+
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: Date.now() - t0 };
|
|
737
751
|
}
|
|
738
752
|
// (from any state: a law about states proven with the others stated beside it, as one inductive set)
|
|
739
753
|
const beside = () => (ctx?.together ?? []).filter(m => m.name !== l.name).flatMap(m => { try {
|
|
@@ -751,9 +765,9 @@ function prove(x0, l, ms, proven, ctx) {
|
|
|
751
765
|
}
|
|
752
766
|
// (from any state: a step that breaks the law from a state the laws allow refutes it, reachable or not; the run that
|
|
753
767
|
// 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) {
|
|
768
|
+
if (ctx?.from && !v.proven && !v.run && !v.stopped && v.stuck === 'sat' && v.witness && b) {
|
|
755
769
|
try {
|
|
756
|
-
const r = b.kind === 'law' ? proveRule(x.rule, [...inv, b.law], { search: { ms } }) : proveSteps(x.rule, [...inv, ...proven], [b.law], { search: { ms } });
|
|
770
|
+
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
771
|
if (r.run)
|
|
758
772
|
v = { ...v, run: r.run };
|
|
759
773
|
}
|
|
@@ -761,7 +775,7 @@ function prove(x0, l, ms, proven, ctx) {
|
|
|
761
775
|
if (!v.run)
|
|
762
776
|
v = { ...v, why: `broken from a state the laws allow (from = "any"), no run from the start found reaching it` };
|
|
763
777
|
}
|
|
764
|
-
const brokenAt = !!(ctx?.from && !v.proven && !v.run && v.stuck === 'sat' && v.witness);
|
|
778
|
+
const brokenAt = !!(ctx?.from && !v.proven && !v.run && !searchOf(v).stopped && v.stuck === 'sat' && v.witness);
|
|
765
779
|
let verdict = v.proven && v.checked && !(ctx?.from && v.assumes) ? 'proven' : v.run || brokenAt ? 'broken' : 'unknown', replayed;
|
|
766
780
|
if (v.translation === 'unchecked')
|
|
767
781
|
verdict = 'unknown';
|
|
@@ -796,12 +810,13 @@ function prove(x0, l, ms, proven, ctx) {
|
|
|
796
810
|
fs.writeFileSync(cert, JSON.stringify(doc));
|
|
797
811
|
}
|
|
798
812
|
}
|
|
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('; ') } : {}),
|
|
813
|
+
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('; ')) } : {}),
|
|
800
814
|
...(v.run && !two ? { assumes: assumedOf(x, v.run) } : {}), ...(found?.length ? { found } : {}), ...(cert ? { cert } : {}), ms: Date.now() - t0 };
|
|
801
815
|
}
|
|
802
816
|
// 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
817
|
// lifted to every call at once; proven of the system, a run shown as the calls' steps.
|
|
804
818
|
function proveInEnv(x, l, ms, proven, ctx) {
|
|
819
|
+
const work = ctx.work;
|
|
805
820
|
const t0 = Date.now(), sys = ctx.sys, base = { name: l.name, expr: l.expr, ...(l.where ? { where: l.where } : {}) };
|
|
806
821
|
if (isLeadsTo(l.expr) || isTwoRuns(l.expr))
|
|
807
822
|
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 };
|
|
@@ -819,18 +834,18 @@ function proveInEnv(x, l, ms, proven, ctx) {
|
|
|
819
834
|
try {
|
|
820
835
|
if (b.kind === 'law') {
|
|
821
836
|
law = bw ? b.law : sys.law(b.law);
|
|
822
|
-
v = proveRule(sys.rule, [...inv, law], { search: { ms } });
|
|
837
|
+
v = proveRule(sys.rule, [...inv, law], { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs });
|
|
823
838
|
}
|
|
824
839
|
else {
|
|
825
840
|
law = sys.step(b.law);
|
|
826
|
-
v = proveSteps(sys.rule, [...inv, ...proven], [law], { search: { ms } });
|
|
841
|
+
v = proveSteps(sys.rule, [...inv, ...proven], [law], { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs });
|
|
827
842
|
}
|
|
828
843
|
}
|
|
829
844
|
catch (e) {
|
|
830
845
|
return { ...base, kind: b.kind, verdict: 'unknown', why: e.message, ms: Date.now() - t0 };
|
|
831
846
|
}
|
|
832
847
|
// (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) {
|
|
848
|
+
if (work === undefined && !v.stopped && !(v.proven && v.checked) && !v.run) {
|
|
834
849
|
const run = contend(sys, law, { ms: Math.min(ms, 10_000) });
|
|
835
850
|
if (run)
|
|
836
851
|
v = { ...v, run: run };
|
|
@@ -839,7 +854,7 @@ function proveInEnv(x, l, ms, proven, ctx) {
|
|
|
839
854
|
if (verdict === 'proven' && b.kind === 'law')
|
|
840
855
|
proven.push(law);
|
|
841
856
|
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 };
|
|
857
|
+
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: Date.now() - t0 };
|
|
843
858
|
}
|
|
844
859
|
// A run of the system as each call's steps: a call begins with its request, reads, commits; a store's key expires.
|
|
845
860
|
function sysRunOf(x, sys, run) {
|
|
@@ -1072,11 +1087,23 @@ function printRule(r, o) {
|
|
|
1072
1087
|
out(` proven with what the search found: ${l.found.join('; ')}`);
|
|
1073
1088
|
if (l.why && l.verdict !== 'proven')
|
|
1074
1089
|
out(` ${l.why}`);
|
|
1090
|
+
if (l.stopped && l.termination) {
|
|
1091
|
+
out(` stopped: true; ${terminationWhy(l.termination)}`);
|
|
1092
|
+
if (l.context)
|
|
1093
|
+
out(` search context (not a reachable run): ${JSON.stringify(l.context)}`);
|
|
1094
|
+
}
|
|
1075
1095
|
if (l.translationWitness)
|
|
1076
1096
|
out(` translation witness: ${JSON.stringify(l.translationWitness)}`);
|
|
1077
1097
|
if (proposed)
|
|
1078
1098
|
out(` ${l.where}`);
|
|
1079
1099
|
};
|
|
1100
|
+
for (const a of r.supportAttempts ?? []) {
|
|
1101
|
+
out(` optional support ${a.name}: ${a.proven && a.checked ? 'proven' : 'not proven'}${a.stopped && a.termination ? `; stopped: true; ${terminationWhy(a.termination)}` : ''}`);
|
|
1102
|
+
if (a.why || a.failure)
|
|
1103
|
+
out(` ${a.why ?? `${a.failure.name}: ${a.failure.message}`}`);
|
|
1104
|
+
if (a.context)
|
|
1105
|
+
out(` context: ${JSON.stringify(a.context)}`);
|
|
1106
|
+
}
|
|
1080
1107
|
if (r.laws.length) {
|
|
1081
1108
|
out(' laws stated in the code:');
|
|
1082
1109
|
for (const l of r.laws)
|
|
@@ -1101,7 +1128,7 @@ function printRule(r, o) {
|
|
|
1101
1128
|
out();
|
|
1102
1129
|
}
|
|
1103
1130
|
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]
|
|
1131
|
+
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
1132
|
gdp-wired lift <capsule> <source.json> [--out DIR] [--emit-only] [--sha256 HASH] [--json]
|
|
1106
1133
|
gdp-wired mutate <config.json> [--json]
|
|
1107
1134
|
gdp-wired draft <file> --clause <text> | --clause-file <file> --cite <ref> [--llm <command> | --answer <file>] [--by <who>]
|
|
@@ -1120,6 +1147,15 @@ not authenticated identities. State the intended policy with gdp: law comments;
|
|
|
1120
1147
|
// Every target's rules and their laws, and the exit code (1: a stated law broken; 2: one not checked).
|
|
1121
1148
|
export async function check(targets, given = {}, each) {
|
|
1122
1149
|
const o = { ms: 10_000, propose: true, ...given }, all = [];
|
|
1150
|
+
validateWatchdog(o.watchdogMs);
|
|
1151
|
+
if (o.work !== undefined) {
|
|
1152
|
+
if (given.ms !== undefined)
|
|
1153
|
+
throw new RangeError('choose a work budget or a legacy ms budget, not both');
|
|
1154
|
+
if (!Number.isSafeInteger(o.work) || o.work < 0)
|
|
1155
|
+
throw new RangeError('work budget must be a nonnegative safe integer');
|
|
1156
|
+
if (o.propose || o.security)
|
|
1157
|
+
throw new RangeError('explicit work check requires propose: false and does not support security proposals');
|
|
1158
|
+
}
|
|
1123
1159
|
for (const p of targets)
|
|
1124
1160
|
for (const t of targetsOf(p)) {
|
|
1125
1161
|
const rs = await checkTarget(t, o);
|
|
@@ -1128,7 +1164,8 @@ export async function check(targets, given = {}, each) {
|
|
|
1128
1164
|
rs.forEach(each);
|
|
1129
1165
|
}
|
|
1130
1166
|
const stated = all.flatMap(r => r.laws);
|
|
1131
|
-
|
|
1167
|
+
// A sampled source translation cannot turn an unknown proof into a successful check.
|
|
1168
|
+
return { rules: all, exit: stated.some(l => l.verdict === 'unknown' || l.translation === 'unchecked' || l.translation === 'error') ? 2 : stated.some(l => l.verdict === 'broken') ? 1 : stated.some(l => l.verdict === 'not read') || o.security && all.some(r => !r.ok) ? 2 : 0 };
|
|
1132
1169
|
}
|
|
1133
1170
|
// --- draft: laws from a clause, for a person to review ----------------------------------------------------------------
|
|
1134
1171
|
// gdp-wired draft <file> --clause <text> | --clause-file <f> --cite <ref> [--llm <command> | --answer <file>] [--by <who>]:
|
|
@@ -1181,7 +1218,8 @@ async function draft(target, o) {
|
|
|
1181
1218
|
export async function main(argv) {
|
|
1182
1219
|
if (argv[0] === 'lift')
|
|
1183
1220
|
return (await import("./lift-cli.js")).liftMain(argv.slice(1));
|
|
1184
|
-
const { cmd, targets, o } = args(argv);
|
|
1221
|
+
const { cmd, targets, o: given } = args(argv);
|
|
1222
|
+
const o = { ms: 10_000, propose: true, ...given };
|
|
1185
1223
|
if (cmd === 'mutate' && targets.length === 1) {
|
|
1186
1224
|
const { checkMutations } = await import("./mutate.js");
|
|
1187
1225
|
const file = path.resolve(targets[0]), config = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
@@ -1196,7 +1234,7 @@ export async function main(argv) {
|
|
|
1196
1234
|
return cmd === 'help' || cmd === '--help' || cmd === '-h' || !cmd ? 0 : 2;
|
|
1197
1235
|
}
|
|
1198
1236
|
tint = colors(proc.env, !!proc.stdout.isTTY, !!o.json);
|
|
1199
|
-
const { rules: all, exit: code0 } = await check(targets,
|
|
1237
|
+
const { rules: all, exit: code0 } = await check(targets, given, o.json ? undefined : r => printRule(r, o));
|
|
1200
1238
|
const stated = all.flatMap(r => r.laws);
|
|
1201
1239
|
const { reviewOf } = await import("./draft.js"), unreviewed = stated.filter(l => (l.cites ?? []).some(c => reviewOf(c) === 'unreviewed'));
|
|
1202
1240
|
const code = code0 === 0 && o.requireReview && unreviewed.length ? 2 : code0;
|
package/dist/core/discover.d.ts
CHANGED
|
@@ -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
|
|
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[];
|
package/dist/core/discover.js
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
// out.verdict // the laws, proven of out.rule: r with its functions and lists made again with the lemmas
|
|
12
12
|
// out.found // per function or list, the lemmas found, as source to paste into recur(...) or carriesList(...)
|
|
13
13
|
import { quietly } from "./cyclic.js";
|
|
14
|
+
import { BudgetExpired, checkBudget, checkWorkEndpoint, withBudget } from "./wall.js";
|
|
15
|
+
import { workContext, workRefusalWhy } from "./work-refusal.js";
|
|
16
|
+
import { WatchdogExpired, checkWatchdog, withSearchWatchdog } from "./search-watchdog.js";
|
|
17
|
+
import { searchContext, stoppedSearch } from "./search-termination.js";
|
|
14
18
|
import { any, atMost, compileFunction, evalC, evalE, n, plus, prod, same, seeded, times, x } from "./machine.js";
|
|
15
19
|
import { Unproven, lit, proveFold, proveSteps, recur, recurOf } from "./dsl.js";
|
|
16
20
|
import { gcd, plus as addLin } from "./solver.js";
|
|
@@ -310,13 +314,56 @@ function houdiniList(r, part, cands, params) {
|
|
|
310
314
|
}
|
|
311
315
|
return undefined;
|
|
312
316
|
}
|
|
313
|
-
//
|
|
314
|
-
//
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
// The optional fifth argument bounds the entire discovery, including sampling,
|
|
318
|
+
// candidate proofs and minimization. Nested calls keep the enclosing authority.
|
|
319
|
+
export function discover(r, laws, stepLaws = [], first, opts = {}) {
|
|
320
|
+
let completed, initial = first;
|
|
321
|
+
const run = () => {
|
|
322
|
+
checkWorkEndpoint('discovery entry');
|
|
323
|
+
const normalized = r.withSumsOf(laws, stepLaws);
|
|
324
|
+
const result = quietly(() => {
|
|
325
|
+
initial ??= proveSteps(normalized, laws, stepLaws, { search: false });
|
|
326
|
+
return discoverSearch(normalized, laws, stepLaws, initial);
|
|
327
|
+
});
|
|
328
|
+
// Record completion only after counted authority has accepted its cost.
|
|
329
|
+
// A later own safety-clock observation must not overwrite that evidence.
|
|
330
|
+
checkBudget('discovery result');
|
|
331
|
+
completed = result;
|
|
332
|
+
checkWatchdog('discovery result');
|
|
333
|
+
return result;
|
|
334
|
+
};
|
|
335
|
+
const work = () => {
|
|
336
|
+
if (opts.work === undefined)
|
|
337
|
+
return run();
|
|
338
|
+
try {
|
|
339
|
+
return withBudget(opts.work, run);
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
if (!(error instanceof BudgetExpired))
|
|
343
|
+
throw error;
|
|
344
|
+
// Only work authority is checked here: an OWN watchdog may have
|
|
345
|
+
// expired after the actual BudgetExpired. Record its work cause before
|
|
346
|
+
// the outer safety scope unwinds/rechecks any ancestor watchdog.
|
|
347
|
+
checkBudget(error.phase);
|
|
348
|
+
const context = workContext(error) ?? (initial ? searchContext(initial) : undefined);
|
|
349
|
+
return { rule: r, found: {}, verdict: { proven: false, checked: false, stuck: 'unknown', why: workRefusalWhy(error), stopped: true,
|
|
350
|
+
termination: { kind: 'work-exhausted', phase: error.phase, scope: 'search' }, ...(context ? { context } : {}) } };
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
try {
|
|
354
|
+
return withSearchWatchdog(opts.watchdogMs, () => completed = work());
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
if (!(error instanceof WatchdogExpired))
|
|
358
|
+
throw error;
|
|
359
|
+
checkWatchdog(error.termination.phase); // an expired ancestor must not return through this helper
|
|
360
|
+
checkBudget(error.termination.phase); // neither may a work owner hidden by the child's own watchdog
|
|
361
|
+
// The final scope guard may observe expiry after the synchronous request
|
|
362
|
+
// already finished. No search was interrupted then; retain its real result.
|
|
363
|
+
if (completed)
|
|
364
|
+
return completed;
|
|
365
|
+
return { rule: r, found: {}, verdict: stoppedSearch({ proven: false, checked: false, stuck: 'unknown', ...(initial ? { context: searchContext(initial) } : {}) }, error.termination) };
|
|
366
|
+
}
|
|
320
367
|
}
|
|
321
368
|
function discoverSearch(r, laws, stepLaws, first) {
|
|
322
369
|
if (first.proven && first.checked)
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { type WorkAmount } from './work-amount.js';
|
|
2
|
+
export declare function remainingStageWork(requested: number | WorkAmount, parts: number): number | WorkAmount;
|
|
3
|
+
export declare function withStageWork<T, F>(units: number | WorkAmount, run: () => T, refused: () => F): T | F;
|
|
1
4
|
export declare function withStageDeadline<T, F>(until: number, run: () => T, refused: () => F): T | F;
|
|
2
5
|
export declare function withStageAllowance<T, F>(ms: number, run: () => T, refused: () => F): T | F;
|
|
3
6
|
export declare function withStageWall<T, F>(until: number, run: () => T, refused: () => F): T | F;
|
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
// Soft search limits are not replacements for the caller's work budget.
|
|
2
2
|
// Legacy mode executes the identical polling path. Full accounting consumes
|
|
3
3
|
// only authenticated refusals belonging to this stage's own endpoint.
|
|
4
|
-
import { budgetEnd, clock, fullRate, inWorkScope, withDeadline, withWall, wallDeadline } from "../kernel/prove.js";
|
|
4
|
+
import { budgetEnd, clock, fullRate, inWorkScope, withDeadline, withWall, wallDeadline, remainingWork } from "../kernel/prove.js";
|
|
5
5
|
import { workLedger } from "./work-admission.js";
|
|
6
|
-
import { workFromNumber, workMultiply } from "./work-amount.js";
|
|
6
|
+
import { minWork, workDivide, workFromNumber, workMultiply } from "./work-amount.js";
|
|
7
7
|
import { completeWorkProfile } from "./work-profile.js";
|
|
8
8
|
import { inProxySearch } from "./search-policy.js";
|
|
9
|
+
import { BudgetExpired, checkWorkEndpoint, withBudget } from "./wall.js";
|
|
10
|
+
// Divide what the enclosing owner can still grant, not the original request.
|
|
11
|
+
// An earlier phase may already have used almost all of that original allowance.
|
|
12
|
+
export function remainingStageWork(requested, parts) {
|
|
13
|
+
if (!Number.isFinite(parts) || parts <= 0)
|
|
14
|
+
throw new RangeError('stage divisor must be positive and finite');
|
|
15
|
+
if (typeof requested === 'number')
|
|
16
|
+
return Math.min(requested, remainingWork()) / parts;
|
|
17
|
+
const available = workLedger.available();
|
|
18
|
+
return workDivide(available === null ? requested : minWork(requested, available), workFromNumber(parts));
|
|
19
|
+
}
|
|
20
|
+
// A bounded deterministic attempt may decline without consuming the parent's
|
|
21
|
+
// remaining search. A root/ancestor refusal must still reach its own owner.
|
|
22
|
+
export function withStageWork(units, run, refused) {
|
|
23
|
+
try {
|
|
24
|
+
return withBudget(units, run);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (!(error instanceof BudgetExpired))
|
|
28
|
+
throw error;
|
|
29
|
+
checkWorkEndpoint(error.phase);
|
|
30
|
+
return refused();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
9
33
|
export function withStageDeadline(until, run, refused) {
|
|
10
34
|
if (!completeWorkProfile.enabled || inProxySearch())
|
|
11
35
|
return withDeadline(until, run);
|
package/dist/core/dsl.d.ts
CHANGED
|
@@ -922,7 +922,8 @@ export declare class LoopRule<P extends Obj = {}, I extends Obj = {}, S extends
|
|
|
922
922
|
randomInput(rand: Rand, bound: number): Record<string, number>;
|
|
923
923
|
}
|
|
924
924
|
export declare const loop: (name: string) => LoopRule;
|
|
925
|
-
export type
|
|
925
|
+
export type { SearchTermination, SearchContext, SearchTerminationFields } from './search-termination.js';
|
|
926
|
+
export type Verdict = TranslationFields & import('./search-termination.ts').SearchTerminationFields & {
|
|
926
927
|
proven: boolean;
|
|
927
928
|
checked: boolean;
|
|
928
929
|
stuck?: string;
|
|
@@ -970,6 +971,7 @@ export type CandidateSeedAudit = {
|
|
|
970
971
|
reason?: string;
|
|
971
972
|
};
|
|
972
973
|
export type ProveOptions = {
|
|
974
|
+
watchdogMs?: number;
|
|
973
975
|
search?: boolean | {
|
|
974
976
|
ms?: number;
|
|
975
977
|
work?: number | WorkAmount;
|