gdp-wired 0.50.3 → 0.50.5
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 -0
- package/dist/core/agent-consult/cli.d.ts +2 -0
- package/dist/core/agent-consult/cli.js +19 -0
- package/dist/core/agent-consult/protocol.d.ts +93 -0
- package/dist/core/agent-consult/protocol.js +154 -0
- package/dist/core/agent-consult/service.d.ts +435 -0
- package/dist/core/agent-consult/service.js +84 -0
- package/dist/core/agent-consult/session.d.ts +13 -0
- package/dist/core/agent-consult/session.js +163 -0
- package/dist/core/agent-consult/source-service.d.ts +83 -0
- package/dist/core/agent-consult/source-service.js +51 -0
- package/dist/core/agent-consult/tsconfig.json +5 -0
- package/dist/core/agent-consult/worker.d.ts +1 -0
- package/dist/core/agent-consult/worker.js +17 -0
- package/dist/core/agent-consult/workspace.d.ts +27 -0
- package/dist/core/agent-consult/workspace.js +66 -0
- package/dist/core/agent-consult.d.ts +8 -0
- package/dist/core/agent-consult.js +6 -0
- package/dist/core/cli.d.ts +5 -0
- package/dist/core/cli.js +118 -49
- package/dist/core/extract-check.d.ts +1 -0
- package/dist/core/extract-check.js +4 -4
- package/dist/core/extract-py.js +11 -1
- package/dist/core/extract-step.js +3 -3
- package/dist/core/py/harness.py +125 -16
- package/docs/agent-consult-workspace-check.md +118 -0
- package/docs/agent-consult.md +151 -0
- package/examples/agent-consult.json +22 -0
- package/package.json +11 -3
package/dist/core/cli.js
CHANGED
|
@@ -9,12 +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";
|
|
13
14
|
import { terminationWhy } from "./search-termination.js";
|
|
14
15
|
import { validateWatchdog } from "./search-watchdog.js";
|
|
15
16
|
import { sourceDiagnostic } from "./source-diagnostic.js";
|
|
16
17
|
import { LawError, buildLaw, buildLeadsTo, buildTwoRuns, citesIn, isLeadsTo, isTwoRuns, lawsIn, namesWithClock } from "./laws.js";
|
|
17
|
-
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();
|
|
18
26
|
import { contend, envOf, inEnv, shrinkRun } from "./system.js";
|
|
19
27
|
const proc = globalThis.process;
|
|
20
28
|
const fs = proc.getBuiltinModule('node:fs'), path = proc.getBuiltinModule('node:path');
|
|
@@ -105,7 +113,8 @@ async function extractOne(t, o) {
|
|
|
105
113
|
}
|
|
106
114
|
// A TypeScript file's relative imports, read beside it as TypeScript resolves them (two deep, at most 12 files), by their
|
|
107
115
|
// path from the file's directory: their classes and functions are the code's own, read and inlined, not another module's.
|
|
108
|
-
function relativeImports(entry) {
|
|
116
|
+
function relativeImports(entry, guard) {
|
|
117
|
+
guard?.(entry);
|
|
109
118
|
const out = {}, seen = new Set([entry]), queue = [[entry, 1]], dir = path.dirname(entry);
|
|
110
119
|
while (queue.length && Object.keys(out).length < 12) {
|
|
111
120
|
const [from, depth] = queue.shift();
|
|
@@ -114,6 +123,7 @@ function relativeImports(entry) {
|
|
|
114
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());
|
|
115
124
|
if (!hit || seen.has(hit) || Object.keys(out).length >= 12)
|
|
116
125
|
continue;
|
|
126
|
+
guard?.(hit);
|
|
117
127
|
seen.add(hit);
|
|
118
128
|
out[path.relative(dir, hit)] = fs.readFileSync(hit, 'utf8');
|
|
119
129
|
if (depth < 2)
|
|
@@ -193,6 +203,10 @@ async function extractWith(t, o) {
|
|
|
193
203
|
}
|
|
194
204
|
}
|
|
195
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: {} };
|
|
196
210
|
// (the first of the three in a directory that holds gdp's options)
|
|
197
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'))));
|
|
198
212
|
const dir = up(from, d => !!holder(d));
|
|
@@ -293,9 +307,7 @@ const searchOf = (v) => v.stopped && v.termination && !(v.proven && v.checked) &
|
|
|
293
307
|
? { stopped: true, termination: v.termination, ...(v.context ? { context: v.context } : {}) } : {};
|
|
294
308
|
const whyOf = (v, semantic) => searchOf(v).termination && v.translation !== 'unchecked' && v.translation !== 'error'
|
|
295
309
|
? terminationWhy(v.termination) : semantic;
|
|
296
|
-
|
|
297
|
-
// overload on the caller's behalf or let a successful variant hide another variant's refusal.
|
|
298
|
-
async function expandInitializers(t, o, laws, rows) {
|
|
310
|
+
function* expandInitializers(t, o, laws, rows) {
|
|
299
311
|
if (!rows.some(r => r.x.initializers))
|
|
300
312
|
return rows;
|
|
301
313
|
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
|
|
@@ -324,27 +336,27 @@ async function expandInitializers(t, o, laws, rows) {
|
|
|
324
336
|
const opts = merge(merge({ ...shared, keep }, cfg.rules[entry] || {}), flags);
|
|
325
337
|
// A rule-specific constructor choice discovered after entry inference still takes precedence.
|
|
326
338
|
if (opts.ctor !== undefined) {
|
|
327
|
-
out.push({ entry, x:
|
|
339
|
+
out.push({ entry, x: yield { target: t, options: { ...opts, entry: variants.entry } } });
|
|
328
340
|
continue;
|
|
329
341
|
}
|
|
330
342
|
for (const ctor of [...new Set(variants.selectors)]) {
|
|
331
|
-
const x =
|
|
343
|
+
const x = yield { target: t, options: { ...opts, entry: variants.entry, ctor } };
|
|
332
344
|
x.notes.push(`initializer ${ctor}: separate scope; every initializer is required for coverage of the class`);
|
|
333
345
|
out.push({ entry, ctor, x });
|
|
334
346
|
}
|
|
335
347
|
}
|
|
336
348
|
return out;
|
|
337
349
|
}
|
|
338
|
-
|
|
339
|
-
const got =
|
|
350
|
+
function* rulesOf(t, o, laws) {
|
|
351
|
+
const got = yield* rulesOf0(t, o, laws);
|
|
340
352
|
if (o.entry)
|
|
341
|
-
return expandInitializers(t, o, laws, got);
|
|
353
|
+
return yield* expandInitializers(t, o, laws, got);
|
|
342
354
|
// (a function that is a request of a rule read, a C file's globals', is read with it)
|
|
343
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 ?? [] : []; };
|
|
344
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)));
|
|
345
357
|
const more = [...new Set(laws.map(l => l.cls ?? l.fn).filter((n) => !!n && !have.has(n)))];
|
|
346
358
|
if (!more.length)
|
|
347
|
-
return expandInitializers(t, o, laws, got);
|
|
359
|
+
return yield* expandInitializers(t, o, laws, got);
|
|
348
360
|
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
|
|
349
361
|
void _j;
|
|
350
362
|
void _m;
|
|
@@ -357,11 +369,13 @@ async function rulesOf(t, o, laws) {
|
|
|
357
369
|
void _k;
|
|
358
370
|
void _f;
|
|
359
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])))];
|
|
360
|
-
const extra =
|
|
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 } } });
|
|
361
375
|
// (the first rule, read with no entry named, kept only where it read something or nothing else was)
|
|
362
|
-
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]);
|
|
363
377
|
}
|
|
364
|
-
|
|
378
|
+
function* rulesOf0(t, o, laws) {
|
|
365
379
|
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
|
|
366
380
|
void _j;
|
|
367
381
|
void _m;
|
|
@@ -378,24 +392,27 @@ async function rulesOf0(t, o, laws) {
|
|
|
378
392
|
// (the names the laws read, so an argument a law reads stays in the rule though the code ignores it)
|
|
379
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])))];
|
|
380
394
|
const optsFor = (entry) => merge(merge({ ...shared, keep }, (entry && cfg.rules[entry]) || {}), flags);
|
|
381
|
-
const one =
|
|
382
|
-
const x =
|
|
383
|
-
|
|
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 };
|
|
384
399
|
};
|
|
400
|
+
const manyOf = function* (entries) { const rows = []; for (const entry of entries)
|
|
401
|
+
rows.push(yield* one(entry)); return rows; };
|
|
385
402
|
const given = o.entry ?? cfg.all.entry;
|
|
386
403
|
if (given)
|
|
387
|
-
return [
|
|
404
|
+
return [yield* one(given)];
|
|
388
405
|
if (t.lang === 'ts' || t.lang === 'cpp') {
|
|
389
406
|
const code = t.files.map(f => fs.readFileSync(f, 'utf8')).join('\n');
|
|
390
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;
|
|
391
408
|
// (C++: a class its source file defines methods of, `Alarm::detected(...) {`, declared in its header)
|
|
392
409
|
const defs = t.lang === 'cpp' ? [...code.matchAll(/^[\w:<>*&\s]*?\b(\w+)::~?\w+\s*\([^;]*?\)\s*(?:const\s*)?(?::[^{;]*)?\{/gm)].map(m => m[1]) : [];
|
|
393
410
|
const cands = [...new Set([...[...code.matchAll(re)].map(m => m[1] ?? m[2]), ...defs])];
|
|
394
|
-
const all =
|
|
411
|
+
const all = yield* manyOf(cands);
|
|
395
412
|
const good = all.filter(r => r.x.ok);
|
|
396
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: [] } }];
|
|
397
414
|
}
|
|
398
|
-
const first =
|
|
415
|
+
const first = yield* one();
|
|
399
416
|
if (first.x.ok)
|
|
400
417
|
return [first];
|
|
401
418
|
// (refused with no entry named: the rules gdp.toml names that the code has, each with its options)
|
|
@@ -405,7 +422,7 @@ async function rulesOf0(t, o, laws) {
|
|
|
405
422
|
const many = /several (?:classes|structs) (?:write their state|written by the file's functions) \(([^)]*)\)/.exec(first.x.refusals[0]?.what ?? '')?.[1].split(', ') ?? [];
|
|
406
423
|
const fns0 = [...new Set(laws.filter(l => !l.cls && l.fn).map(l => l.fn))];
|
|
407
424
|
if (named.length)
|
|
408
|
-
return
|
|
425
|
+
return yield* manyOf([...new Set([...many, ...named, ...fns0])]);
|
|
409
426
|
// (a contract's file names its contracts: refused with none named, the refusal is the rule's)
|
|
410
427
|
if (t.lang === 'solidity')
|
|
411
428
|
return [first];
|
|
@@ -413,7 +430,7 @@ async function rulesOf0(t, o, laws) {
|
|
|
413
430
|
const what = first.x.refusals[0]?.what ?? '';
|
|
414
431
|
const several = /several (?:classes|structs) (?:write their state|written by the file's functions) \(([^)]*)\)/.exec(what)?.[1].split(', ') ?? [];
|
|
415
432
|
const fns = [...new Set(laws.filter(l => !l.cls && l.fn).map(l => l.fn))];
|
|
416
|
-
return several.length || fns.length ?
|
|
433
|
+
return several.length || fns.length ? yield* manyOf([...several, ...fns]) : [first];
|
|
417
434
|
}
|
|
418
435
|
// (a class statement's name: its keyword at the start of a line, after modifiers; never a word in a comment)
|
|
419
436
|
const classAt = (line) => {
|
|
@@ -512,9 +529,65 @@ export function scoped(file) {
|
|
|
512
529
|
return { ...l, ...(cls ? { cls } : {}), ...(fn ? { fn } : {}) };
|
|
513
530
|
});
|
|
514
531
|
}
|
|
532
|
+
// Both drivers consume the same enumeration, configuration and proof/proposal algorithm.
|
|
515
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) {
|
|
516
589
|
const laws = t.files.flatMap(scoped), cites = t.files.flatMap(f => citesIn(fs.readFileSync(f, 'utf8'), path.basename(f)));
|
|
517
|
-
const rules =
|
|
590
|
+
const rules = yield* rulesOf(t, o, laws);
|
|
518
591
|
const outs = [];
|
|
519
592
|
// (the clock's unit, for durations in a law: the language's clock, or clock = "s" | "ms" in gdp.toml or --clock)
|
|
520
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];
|
|
@@ -544,12 +617,8 @@ export async function checkTarget(t, o) {
|
|
|
544
617
|
continue;
|
|
545
618
|
}
|
|
546
619
|
// (an Effect service's primitives: the lemmas of their use proven first, each proven one beside every law)
|
|
547
|
-
if (x.lemmas?.length)
|
|
548
|
-
|
|
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 } : {}) }));
|
|
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}`)];
|
|
552
|
-
}
|
|
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 };
|
|
553
622
|
const ev = x.evidence;
|
|
554
623
|
if (ev)
|
|
555
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)` : ''}`;
|
|
@@ -621,11 +690,11 @@ export async function checkTarget(t, o) {
|
|
|
621
690
|
if (o.security) {
|
|
622
691
|
// Deliberately separate from accepted policy and from heuristic proposals that hide broken guesses.
|
|
623
692
|
// Do not pass previously proven candidates as hypotheses; use the same environment/replay as stated laws.
|
|
624
|
-
const candidates = securityTemplates(x), until =
|
|
625
|
-
r.security = candidates.map(l => ({ ...(
|
|
693
|
+
const candidates = securityTemplates(x), until = cliNow() + o.ms;
|
|
694
|
+
r.security = candidates.map(l => ({ ...(cliNow() >= until
|
|
626
695
|
? { name: l.name, expr: l.expr, verdict: 'unknown', why: 'security proposal budget exhausted', ms: 0 }
|
|
627
|
-
: sys ? proveInEnv(x, l, Math.max(1, Math.min(2000, until -
|
|
628
|
-
: prove(x, l, Math.max(1, Math.min(2000, until -
|
|
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 })),
|
|
629
698
|
securityKind: l.securityKind, review: l.review,
|
|
630
699
|
where: `${l.method ? `above ${l.method}: ` : ''}${COMMENT[t.lang]} gdp: law ${l.name}: ${l.expr}` }));
|
|
631
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');
|
|
@@ -695,7 +764,7 @@ function ruleFor(x, expr) {
|
|
|
695
764
|
}
|
|
696
765
|
function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
697
766
|
const x = ruleFor(x0, l.expr);
|
|
698
|
-
const t0 =
|
|
767
|
+
const t0 = cliNow(), cites = ctx?.cites.filter(c => c.law === l.name).map(c => c.text) ?? [];
|
|
699
768
|
const base = { name: l.name, expr: l.expr, ...(l.where ? { where: l.where } : {}), ...(cites.length ? { cites } : {}) };
|
|
700
769
|
const inv = x.invariants ?? [], search = { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs, ...(ctx?.from ? { from: ctx.from } : {}) };
|
|
701
770
|
// (whenever <from>, later <to>: proven with the rule's invariants and the laws proven so far, each helpful request fair)
|
|
@@ -716,9 +785,9 @@ function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
|
716
785
|
v = proveLeadsTo(x.rule, [...inv, ...proven], lt, { ms });
|
|
717
786
|
}
|
|
718
787
|
catch (e) {
|
|
719
|
-
return { ...base, kind: 'leads to', verdict: 'unknown', why: e.message, ms:
|
|
788
|
+
return { ...base, kind: 'leads to', verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
|
|
720
789
|
}
|
|
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:
|
|
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 };
|
|
722
791
|
}
|
|
723
792
|
let b, two;
|
|
724
793
|
// (a law that can't be built is not read, with why: never the whole check aborted)
|
|
@@ -743,11 +812,11 @@ function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
|
743
812
|
r = proveRule(x.rule, [...inv, b.law], { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs });
|
|
744
813
|
}
|
|
745
814
|
catch (e) {
|
|
746
|
-
return { ...base, kind: 'law', verdict: 'unknown', why: e.message, ms:
|
|
815
|
+
return { ...base, kind: 'law', verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
|
|
747
816
|
}
|
|
748
817
|
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:
|
|
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:
|
|
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 };
|
|
751
820
|
}
|
|
752
821
|
// (from any state: a law about states proven with the others stated beside it, as one inductive set)
|
|
753
822
|
const beside = () => (ctx?.together ?? []).filter(m => m.name !== l.name).flatMap(m => { try {
|
|
@@ -761,7 +830,7 @@ function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
|
761
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);
|
|
762
831
|
}
|
|
763
832
|
catch (e) {
|
|
764
|
-
return { ...base, kind, verdict: 'unknown', why: e.message, ms:
|
|
833
|
+
return { ...base, kind, verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
|
|
765
834
|
}
|
|
766
835
|
// (from any state: a step that breaks the law from a state the laws allow refutes it, reachable or not; the run that
|
|
767
836
|
// reaches one from the start, where the search from the start finds it, is shown with it)
|
|
@@ -811,13 +880,13 @@ function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
|
811
880
|
}
|
|
812
881
|
}
|
|
813
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('; ')) } : {}),
|
|
814
|
-
...(v.run && !two ? { assumes: assumedOf(x, v.run) } : {}), ...(found?.length ? { found } : {}), ...(cert ? { cert } : {}), ms:
|
|
883
|
+
...(v.run && !two ? { assumes: assumedOf(x, v.run) } : {}), ...(found?.length ? { found } : {}), ...(cert ? { cert } : {}), ms: cliNow() - t0 };
|
|
815
884
|
}
|
|
816
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
|
|
817
886
|
// lifted to every call at once; proven of the system, a run shown as the calls' steps.
|
|
818
887
|
function proveInEnv(x, l, ms, proven, ctx) {
|
|
819
888
|
const work = ctx.work;
|
|
820
|
-
const t0 =
|
|
889
|
+
const t0 = cliNow(), sys = ctx.sys, base = { name: l.name, expr: l.expr, ...(l.where ? { where: l.where } : {}) };
|
|
821
890
|
if (isLeadsTo(l.expr) || isTwoRuns(l.expr))
|
|
822
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 };
|
|
823
892
|
// (at most one call between a and b: a flow's mutual exclusion, its leases running out where their keys expire)
|
|
@@ -842,7 +911,7 @@ function proveInEnv(x, l, ms, proven, ctx) {
|
|
|
842
911
|
}
|
|
843
912
|
}
|
|
844
913
|
catch (e) {
|
|
845
|
-
return { ...base, kind: b.kind, verdict: 'unknown', why: e.message, ms:
|
|
914
|
+
return { ...base, kind: b.kind, verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
|
|
846
915
|
}
|
|
847
916
|
// (not proven and no run: calls contending with one request, a run the search's own draws seldom make)
|
|
848
917
|
if (work === undefined && !v.stopped && !(v.proven && v.checked) && !v.run) {
|
|
@@ -854,7 +923,7 @@ function proveInEnv(x, l, ms, proven, ctx) {
|
|
|
854
923
|
if (verdict === 'proven' && b.kind === 'law')
|
|
855
924
|
proven.push(law);
|
|
856
925
|
const found = v.found?.laws?.map(f => f.text);
|
|
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:
|
|
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 };
|
|
858
927
|
}
|
|
859
928
|
// A run of the system as each call's steps: a call begins with its request, reads, commits; a store's key expires.
|
|
860
929
|
function sysRunOf(x, sys, run) {
|
|
@@ -1022,11 +1091,11 @@ function propose(x, lang, o, proven, stated) {
|
|
|
1022
1091
|
add(`${codeOf(v)} never goes down`, `${codeOf(v)} >= old(${codeOf(v)})`);
|
|
1023
1092
|
add(`${codeOf(v)} never goes up`, `${codeOf(v)} <= old(${codeOf(v)})`);
|
|
1024
1093
|
}
|
|
1025
|
-
const shown = [], until =
|
|
1094
|
+
const shown = [], until = cliNow() + Math.max(5000, o.ms * 2);
|
|
1026
1095
|
let broken = 0;
|
|
1027
1096
|
const fixed = new Set();
|
|
1028
|
-
for (const c of cands.slice(0, 40)) {
|
|
1029
|
-
if (
|
|
1097
|
+
for (const c of cands.slice(0, syncControl ? Math.min(40, syncControl.candidates) : 40)) {
|
|
1098
|
+
if (cliNow() > until)
|
|
1030
1099
|
break;
|
|
1031
1100
|
const v = /^(.+) never (?:changes|goes (?:down|up))$/.exec(c.name)?.[1];
|
|
1032
1101
|
if (v && fixed.has(v))
|
|
@@ -1178,7 +1247,7 @@ async function draft(target, o) {
|
|
|
1178
1247
|
out('gdp-wired draft: --clause <text> or --clause-file <file>');
|
|
1179
1248
|
return 2;
|
|
1180
1249
|
}
|
|
1181
|
-
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;
|
|
1182
1251
|
if (!x) {
|
|
1183
1252
|
out(`gdp-wired draft: no rule read from ${target}: ${rules[0]?.x.refusals[0]?.what ?? ''}`);
|
|
1184
1253
|
return 2;
|
|
@@ -645,7 +645,7 @@ export function drive(m, r, sorts, code, opts = {}) {
|
|
|
645
645
|
}
|
|
646
646
|
// Result fields in a prover witness are not state held by a pure
|
|
647
647
|
// function. Compare the returned value below, never carry those fields.
|
|
648
|
-
res = c.ok ? { snap: { leaves: {}, maps: {} }, out: c.value } : { refused: c.error };
|
|
648
|
+
res = c.ok ? { snap: { leaves: {}, maps: {} }, out: c.value, nativeFailed: c.nativeFailed } : { refused: c.error };
|
|
649
649
|
}
|
|
650
650
|
else if (isClass) {
|
|
651
651
|
const self = side.self, c = code.call(self, e, args);
|
|
@@ -657,7 +657,7 @@ export function drive(m, r, sorts, code, opts = {}) {
|
|
|
657
657
|
if (!c.ok)
|
|
658
658
|
res = { refused: c.error };
|
|
659
659
|
else
|
|
660
|
-
res = { snap: code.snapOf(self, params), out: c.value, self };
|
|
660
|
+
res = { snap: code.snapOf(self, params), out: c.value, self, nativeFailed: c.nativeFailed };
|
|
661
661
|
}
|
|
662
662
|
else {
|
|
663
663
|
const c = code.reduce(side.snap, e, args, params);
|
|
@@ -789,7 +789,7 @@ export function drive(m, r, sorts, code, opts = {}) {
|
|
|
789
789
|
});
|
|
790
790
|
const rk = m.results?.[e.call];
|
|
791
791
|
journal.observations.push({ where, method: e.call, before, after, params: { ...params }, inputs: { ...inputs }, bindings: bindings ?? fallback,
|
|
792
|
-
args: nativeArgs ?? [], result, failed: false, ...(observed ? { observed } : {}), ...(code.nativeEquality ? { nativeEquality: code.nativeEquality } : {}), legacyResult: !standalone && rk?.k === 'rec' && rk.fields.some(([field]) => field === 'value') });
|
|
792
|
+
args: nativeArgs ?? [], result, failed: res.nativeFailed ?? false, ...(observed ? { observed } : {}), ...(code.nativeEquality ? { nativeEquality: code.nativeEquality } : {}), legacyResult: !standalone && rk?.k === 'rec' && rk.fields.some(([field]) => field === 'value') });
|
|
793
793
|
}
|
|
794
794
|
next.side = afterSide;
|
|
795
795
|
next.st = rule.st;
|
|
@@ -1055,7 +1055,7 @@ export function drive(m, r, sorts, code, opts = {}) {
|
|
|
1055
1055
|
}
|
|
1056
1056
|
if (!journal.reason)
|
|
1057
1057
|
journal.observations.push({ where: `exhaustive native input ${++ordinal}`, method: event.call,
|
|
1058
|
-
before: {}, after: {}, params: {}, inputs: {}, bindings, args: savedArgs, result, failed: false, ...(observed ? { observed } : {}), ...(code.nativeEquality ? { nativeEquality: code.nativeEquality } : {}) });
|
|
1058
|
+
before: {}, after: {}, params: {}, inputs: {}, bindings, args: savedArgs, result, failed: returned.nativeFailed ?? false, ...(observed ? { observed } : {}), ...(code.nativeEquality ? { nativeEquality: code.nativeEquality } : {}) });
|
|
1059
1059
|
return;
|
|
1060
1060
|
}
|
|
1061
1061
|
for (const value of finite[at])
|
package/dist/core/extract-py.js
CHANGED
|
@@ -26,6 +26,16 @@ export function extractPython(at, opts = {}) {
|
|
|
26
26
|
return { ok: false, refusals: [{ where: e.where, what: e.what }], notes: [] };
|
|
27
27
|
throw e;
|
|
28
28
|
}
|
|
29
|
-
const harness = () =>
|
|
29
|
+
const harness = (read) => {
|
|
30
|
+
const methods = read.cls ? mod.recs[read.cls]?.methods : Object.fromEntries(mod.entries.flatMap(e => e.k === 'func' ? [[mod.funcs[e.id].name, e.id]] : []));
|
|
31
|
+
const nativeMethods = Object.fromEntries(Object.keys(read.args).flatMap(name => {
|
|
32
|
+
const id = methods?.[name], f = id ? mod.funcs[id] : undefined;
|
|
33
|
+
if (!f)
|
|
34
|
+
return [];
|
|
35
|
+
const decorators = f.decorators.map(d => Number(/:(\d+):\d+$/.exec(d.p)?.[1])).filter(Number.isFinite);
|
|
36
|
+
return [[name, { file: f.span[0], line: Math.min(f.span[1], ...decorators) }]];
|
|
37
|
+
}));
|
|
38
|
+
return { cmd: opts.python ?? 'python3', args: [here('harness.py')], env: { PYTHONDONTWRITEBYTECODE: '1', ...(opts.djangoSettings ? { DJANGO_SETTINGS_MODULE: opts.djangoSettings } : {}) }, hello: { root: mod.root, path: mod.path, module: mod.module, nativeMethods } };
|
|
39
|
+
};
|
|
30
40
|
return extractStep(mod, harness, opts);
|
|
31
41
|
}
|
|
@@ -6708,9 +6708,9 @@ function checkStepOnce(h, read, r, sorts, opts) {
|
|
|
6708
6708
|
const out = res.out;
|
|
6709
6709
|
const rk = m.results?.[e.call];
|
|
6710
6710
|
if (!rk)
|
|
6711
|
-
return { ok: true, value: undefined };
|
|
6711
|
+
return { ok: true, value: undefined, nativeFailed: failed };
|
|
6712
6712
|
if (rk.k === 'scalar')
|
|
6713
|
-
return { ok: true, value: value(out) };
|
|
6713
|
+
return { ok: true, value: value(out), nativeFailed: failed };
|
|
6714
6714
|
const o = {};
|
|
6715
6715
|
for (const [f] of rk.fields) {
|
|
6716
6716
|
if (f === 'failed')
|
|
@@ -6724,7 +6724,7 @@ function checkStepOnce(h, read, r, sorts, opts) {
|
|
|
6724
6724
|
if (f.startsWith('effect:'))
|
|
6725
6725
|
o[f] = !!res.effects?.[f.slice(7)];
|
|
6726
6726
|
}
|
|
6727
|
-
return { ok: true, value: o };
|
|
6727
|
+
return { ok: true, value: o, nativeFailed: failed };
|
|
6728
6728
|
},
|
|
6729
6729
|
...(native ? { nativeState: (self) => {
|
|
6730
6730
|
const result = ask({ op: 'native', id: self });
|