gdp-wired 0.44.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -7
- package/dist/core/bitsets.d.ts +2 -0
- package/dist/core/bitsets.js +23 -0
- package/dist/core/bmc.js +6 -2
- package/dist/core/c/reader.d.ts +9 -1
- package/dist/core/c/reader.js +445 -38
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +4 -0
- package/dist/core/cli.js +335 -39
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +5 -2
- package/dist/core/counts.js +335 -88
- package/dist/core/cycles.js +8 -1
- package/dist/core/cyclic.d.ts +1 -0
- package/dist/core/cyclic.js +13 -7
- package/dist/core/data-synth.d.ts +3 -0
- package/dist/core/data-synth.js +252 -0
- package/dist/core/data.d.ts +8 -2
- package/dist/core/data.js +1113 -172
- package/dist/core/discover.js +3 -1
- package/dist/core/draft.d.ts +19 -0
- package/dist/core/draft.js +53 -0
- package/dist/core/dsl.d.ts +39 -3
- package/dist/core/dsl.js +250 -31
- package/dist/core/effect-prims.js +2 -2
- package/dist/core/effect.d.ts +1 -4
- package/dist/core/effect.js +1 -15
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +16 -1
- package/dist/core/exists.js +447 -50
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +185 -31
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +115 -3
- package/dist/core/extract-ex.js +3 -3
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +21 -13
- package/dist/core/extract-go.d.ts +1 -0
- package/dist/core/extract-go.js +58 -9
- package/dist/core/extract-ir.d.ts +1 -0
- package/dist/core/extract-ir.js +15 -0
- package/dist/core/extract-jvm.d.ts +1 -1
- package/dist/core/extract-jvm.js +65 -14
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +23 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +4 -4
- package/dist/core/extract-rb.js +3 -3
- package/dist/core/extract-read.d.ts +25 -0
- package/dist/core/extract-read.js +60 -5
- package/dist/core/extract-rs.js +22 -20
- package/dist/core/extract-shapes.js +22 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +89 -30
- package/dist/core/extract-step.d.ts +201 -4
- package/dist/core/extract-step.js +1514 -111
- package/dist/core/extract-swift.js +24 -13
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/extract.js +88 -7
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/fresh.d.ts +2 -2
- package/dist/core/fresh.js +7 -3
- package/dist/core/go/reader.go +7 -1
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +1020 -246
- package/dist/core/jvm/JavaReader.java +33 -8
- package/dist/core/jvm/Jvm.java +20 -1
- package/dist/core/jvm/KtReader.java +59 -6
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +193 -14
- package/dist/core/machine.d.ts +16 -3
- package/dist/core/machine.js +212 -28
- package/dist/core/nonterm.js +14 -1
- package/dist/core/orm/harness.js +61 -0
- package/dist/core/orm-fixtures/schema.prisma +5 -0
- package/dist/core/py/harness.py +260 -21
- package/dist/core/py/reader.py +278 -39
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/reader-fixtures/README.md +28 -0
- package/dist/core/reader-fixtures/c-693042.cpp +8 -0
- package/dist/core/reader-fixtures/go-685506.go +14 -0
- package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
- package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
- package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
- package/dist/core/reader-fixtures/swift-735726.swift +15 -0
- package/dist/core/reader-fixtures/swift-735990.swift +15 -0
- package/dist/core/reader-fixtures/swift-739158.swift +4 -0
- package/dist/core/reader-fixtures/swift-744834.swift +15 -0
- package/dist/core/reader-fixtures/swift-746946.swift +31 -0
- package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
- package/dist/core/relation.d.ts +1 -1
- package/dist/core/relation.js +29 -2
- package/dist/core/relational.js +4 -2
- package/dist/core/rs/src/main.rs +18 -2
- package/dist/core/sample-cache.d.ts +8 -0
- package/dist/core/sample-cache.js +46 -0
- package/dist/core/security.d.ts +38 -0
- package/dist/core/security.js +88 -0
- package/dist/core/sol/harness.py +63 -7
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +8 -5
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +263 -4
- package/dist/core/transfer.js +39 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +51 -6
- package/dist/interchange/check.js +10 -10
- package/dist/interchange/format.d.ts +4 -0
- package/dist/interchange/format.js +24 -6
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +88 -10
- package/dist/kernel/epr.js +141 -29
- package/dist/kernel/kernel.d.ts +31 -1
- package/dist/kernel/kernel.js +391 -101
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +30 -1
- package/dist/kernel/prove.js +481 -71
- package/dist/kernel/reader.d.ts +3 -0
- package/dist/kernel/reader.js +101 -14
- package/dist/kernel/share.d.ts +1 -0
- package/dist/kernel/share.js +27 -0
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +200 -66
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +7 -2
package/dist/core/cli.js
CHANGED
|
@@ -7,9 +7,12 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
7
7
|
}
|
|
8
8
|
return path;
|
|
9
9
|
};
|
|
10
|
+
import { fiberRun } from "./fiber-run.js";
|
|
11
|
+
import { securityTemplates } from "./security.js";
|
|
10
12
|
import { proveLeadsTo, proveRule, proveSteps } from "./dsl.js";
|
|
11
13
|
import { LawError, buildLaw, buildLeadsTo, buildTwoRuns, citesIn, isLeadsTo, isTwoRuns, lawsIn, namesWithClock } from "./laws.js";
|
|
12
14
|
import { certify, proveTwoRuns } from "./relational.js";
|
|
15
|
+
import { contend, envOf, inEnv, shrinkRun } from "./system.js";
|
|
13
16
|
const proc = globalThis.process;
|
|
14
17
|
const fs = proc.getBuiltinModule('node:fs'), path = proc.getBuiltinModule('node:path');
|
|
15
18
|
const out = (s = '') => proc.stdout.write(`${s}\n`);
|
|
@@ -29,6 +32,10 @@ function args(argv) {
|
|
|
29
32
|
o.json = true;
|
|
30
33
|
else if (a === '--no-propose')
|
|
31
34
|
o.propose = false;
|
|
35
|
+
else if (a === '--security')
|
|
36
|
+
o.security = true;
|
|
37
|
+
else if (a === '--require-review')
|
|
38
|
+
o.requireReview = true;
|
|
32
39
|
else if (a.startsWith('--')) {
|
|
33
40
|
const [k, inline] = a.slice(2).split('='), v = inline ?? argv[++i] ?? '';
|
|
34
41
|
const key = k.replace(/-(\w)/g, (_, c) => c.toUpperCase());
|
|
@@ -93,6 +100,25 @@ async function extractOne(t, o) {
|
|
|
93
100
|
throw e;
|
|
94
101
|
}
|
|
95
102
|
}
|
|
103
|
+
// A TypeScript file's relative imports, read beside it as TypeScript resolves them (two deep, at most 12 files), by their
|
|
104
|
+
// path from the file's directory: their classes and functions are the code's own, read and inlined, not another module's.
|
|
105
|
+
function relativeImports(entry) {
|
|
106
|
+
const out = {}, seen = new Set([entry]), queue = [[entry, 1]], dir = path.dirname(entry);
|
|
107
|
+
while (queue.length && Object.keys(out).length < 12) {
|
|
108
|
+
const [from, depth] = queue.shift();
|
|
109
|
+
for (const m of fs.readFileSync(from, 'utf8').matchAll(/(?:\bfrom\s+|\bimport\s*\(\s*|\brequire\(\s*|^\s*import\s+)['"](\.{1,2}\/[^'"]+)['"]/gm)) {
|
|
110
|
+
const base = path.join(path.dirname(from), m[1]), bare = base.replace(/\.(js|jsx|mjs|cjs)$/, '');
|
|
111
|
+
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());
|
|
112
|
+
if (!hit || seen.has(hit) || Object.keys(out).length >= 12)
|
|
113
|
+
continue;
|
|
114
|
+
seen.add(hit);
|
|
115
|
+
out[path.relative(dir, hit)] = fs.readFileSync(hit, 'utf8');
|
|
116
|
+
if (depth < 2)
|
|
117
|
+
queue.push([hit, depth + 1]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
96
122
|
async function extractWith(t, o) {
|
|
97
123
|
const f = t.at, dir = path.dirname(f);
|
|
98
124
|
switch (t.lang) {
|
|
@@ -158,8 +184,8 @@ async function extractWith(t, o) {
|
|
|
158
184
|
const { extractXState } = await import("./extract-xstate.js"), xstate = await own('xstate');
|
|
159
185
|
return extractXState(file, { ...(xstate ? { xstate } : {}), ...o });
|
|
160
186
|
}
|
|
161
|
-
const { extract } = await import("./extract.js");
|
|
162
|
-
return extract(file, o);
|
|
187
|
+
const { extract } = await import("./extract.js"), files = relativeImports(f);
|
|
188
|
+
return extract(file, { ...(Object.keys(files).length ? { files } : {}), ...o });
|
|
163
189
|
}
|
|
164
190
|
}
|
|
165
191
|
}
|
|
@@ -252,19 +278,59 @@ const merge = (a, b) => {
|
|
|
252
278
|
out[k] = v && typeof v === 'object' && !Array.isArray(v) && out[k] && typeof out[k] === 'object' && !Array.isArray(out[k]) ? merge(out[k], v) : v;
|
|
253
279
|
return out;
|
|
254
280
|
};
|
|
255
|
-
//
|
|
256
|
-
//
|
|
257
|
-
|
|
258
|
-
|
|
281
|
+
// Each initializer is a separate scope, with its own original-code replay and laws. Never choose one
|
|
282
|
+
// overload on the caller's behalf or let a successful variant hide another variant's refusal.
|
|
283
|
+
async function expandInitializers(t, o, laws, rows) {
|
|
284
|
+
if (!rows.some(r => r.x.initializers))
|
|
285
|
+
return rows;
|
|
286
|
+
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
|
|
287
|
+
void _j;
|
|
288
|
+
void _m;
|
|
289
|
+
void _p;
|
|
290
|
+
void _c;
|
|
291
|
+
void _t;
|
|
292
|
+
void _fr;
|
|
293
|
+
void _e;
|
|
294
|
+
const cfg = configFor(t.lang === 'go' || t.lang === 'rust' || fs.statSync(t.at).isDirectory() ? t.at : path.dirname(t.at));
|
|
295
|
+
const { clock: _k, from: _f, env: _v, calendar: _cal, ...shared } = cfg.all;
|
|
296
|
+
void _k;
|
|
297
|
+
void _f;
|
|
298
|
+
void _v;
|
|
299
|
+
void _cal;
|
|
300
|
+
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]))];
|
|
301
|
+
const out = [];
|
|
302
|
+
for (const row of rows) {
|
|
303
|
+
const variants = row.x.initializers;
|
|
304
|
+
if (!variants) {
|
|
305
|
+
out.push(row);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const entry = row.entry ?? variants.name;
|
|
309
|
+
const opts = merge(merge({ ...shared, keep }, cfg.rules[entry] || {}), flags);
|
|
310
|
+
// A rule-specific constructor choice discovered after entry inference still takes precedence.
|
|
311
|
+
if (opts.ctor !== undefined) {
|
|
312
|
+
out.push({ entry, x: await extractOne(t, { ...opts, entry: variants.entry }) });
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
for (const ctor of [...new Set(variants.selectors)]) {
|
|
316
|
+
const x = await extractOne(t, { ...opts, entry: variants.entry, ctor });
|
|
317
|
+
x.notes.push(`initializer ${ctor}: separate scope; every initializer is required for coverage of the class`);
|
|
318
|
+
out.push({ entry, ctor, x });
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return out;
|
|
322
|
+
}
|
|
259
323
|
async function rulesOf(t, o, laws) {
|
|
260
324
|
const got = await rulesOf0(t, o, laws);
|
|
261
325
|
if (o.entry)
|
|
262
|
-
return got;
|
|
263
|
-
|
|
326
|
+
return expandInitializers(t, o, laws, got);
|
|
327
|
+
// (a function that is a request of a rule read, a C file's globals', is read with it)
|
|
328
|
+
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 ?? [] : []; };
|
|
329
|
+
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)));
|
|
264
330
|
const more = [...new Set(laws.map(l => l.cls ?? l.fn).filter((n) => !!n && !have.has(n)))];
|
|
265
331
|
if (!more.length)
|
|
266
|
-
return got;
|
|
267
|
-
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, ...flags } = o;
|
|
332
|
+
return expandInitializers(t, o, laws, got);
|
|
333
|
+
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
|
|
268
334
|
void _j;
|
|
269
335
|
void _m;
|
|
270
336
|
void _p;
|
|
@@ -272,16 +338,16 @@ async function rulesOf(t, o, laws) {
|
|
|
272
338
|
void _t;
|
|
273
339
|
void _fr;
|
|
274
340
|
const cfg = configFor(t.lang === 'go' || t.lang === 'rust' || fs.statSync(t.at).isDirectory() ? t.at : path.dirname(t.at));
|
|
275
|
-
const { clock: _k, from: _f, ...shared } = cfg.all;
|
|
341
|
+
const { clock: _k, from: _f, env: _v, calendar: _cal, ...shared } = cfg.all;
|
|
276
342
|
void _k;
|
|
277
343
|
void _f;
|
|
278
|
-
const keep = [...new Set(laws.flatMap(l => l.expr.match(/[A-Za-z_]\w*/g) ?? []))];
|
|
344
|
+
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])))];
|
|
279
345
|
const extra = await Promise.all(more.map(async (entry) => ({ entry, x: await extractOne(t, { ...merge(merge({ ...shared, keep }, cfg.rules[entry] || {}), flags), entry }) })));
|
|
280
346
|
// (the first rule, read with no entry named, kept only where it read something or nothing else was)
|
|
281
|
-
return [...got.filter(r => r.x.ok || r.entry || !extra.length), ...extra];
|
|
347
|
+
return expandInitializers(t, o, laws, [...got.filter(r => r.x.ok || r.entry || !extra.length), ...extra]);
|
|
282
348
|
}
|
|
283
349
|
async function rulesOf0(t, o, laws) {
|
|
284
|
-
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, ...flags } = o;
|
|
350
|
+
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
|
|
285
351
|
void _j;
|
|
286
352
|
void _m;
|
|
287
353
|
void _p;
|
|
@@ -291,11 +357,11 @@ async function rulesOf0(t, o, laws) {
|
|
|
291
357
|
// (the options: gdp.toml's for every rule, then the rule's own, then the flags; a rule found with no entry named is
|
|
292
358
|
// read again where gdp.toml has options of its own for it)
|
|
293
359
|
const cfg = configFor(t.lang === 'go' || t.lang === 'rust' || fs.statSync(t.at).isDirectory() ? t.at : path.dirname(t.at));
|
|
294
|
-
const { clock: _k, from: _f, ...shared } = cfg.all;
|
|
360
|
+
const { clock: _k, from: _f, env: _v, calendar: _cal, ...shared } = cfg.all;
|
|
295
361
|
void _f;
|
|
296
362
|
void _k;
|
|
297
363
|
// (the names the laws read, so an argument a law reads stays in the rule though the code ignores it)
|
|
298
|
-
const keep = [...new Set(laws.flatMap(l => l.expr.match(/[A-Za-z_]\w*/g) ?? []))];
|
|
364
|
+
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])))];
|
|
299
365
|
const optsFor = (entry) => merge(merge({ ...shared, keep }, (entry && cfg.rules[entry]) || {}), flags);
|
|
300
366
|
const one = async (entry) => {
|
|
301
367
|
const x = await extractOne(t, { ...optsFor(entry), ...(entry ? { entry } : {}) }), found = x.model?.name;
|
|
@@ -307,7 +373,9 @@ async function rulesOf0(t, o, laws) {
|
|
|
307
373
|
if (t.lang === 'ts' || t.lang === 'cpp') {
|
|
308
374
|
const code = t.files.map(f => fs.readFileSync(f, 'utf8')).join('\n');
|
|
309
375
|
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;
|
|
310
|
-
|
|
376
|
+
// (C++: a class its source file defines methods of, `Alarm::detected(...) {`, declared in its header)
|
|
377
|
+
const defs = t.lang === 'cpp' ? [...code.matchAll(/^[\w:<>*&\s]*?\b(\w+)::~?\w+\s*\([^;]*?\)\s*(?:const\s*)?(?::[^{;]*)?\{/gm)].map(m => m[1]) : [];
|
|
378
|
+
const cands = [...new Set([...[...code.matchAll(re)].map(m => m[1] ?? m[2]), ...defs])];
|
|
311
379
|
const all = await Promise.all(cands.map(c => one(c)));
|
|
312
380
|
const good = all.filter(r => r.x.ok);
|
|
313
381
|
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: [] } }];
|
|
@@ -392,12 +460,19 @@ export function scoped(file) {
|
|
|
392
460
|
const code = i === l.line - 1 ? lines[i].replace(/(#|\/\/|--).*$/, '') : lines[i];
|
|
393
461
|
if (i >= l.line && classAt(code))
|
|
394
462
|
break;
|
|
395
|
-
const m = /\b(?:def|defp|fn|fun|func|function)\s+(?:\([^)]*\)\s*)?(?:self\.)?(\w+)|^\s*(?:(?:public|private|protected|static|final|synchronized|async|override|open|suspend|inline|virtual|const|[\w<>[\],?]+)\s+)*(\w+)\s*\(/.exec(code);
|
|
396
|
-
if (m && !m[1] && declares(code, m.index + m[0].length - 1))
|
|
463
|
+
const m = /\b(?:def|defp|fn|fun|func|function)\s+(?:\([^)]*\)\s*)?(?:self\.)?(\w+)|^\s*(?:(?:public|private|protected|static|final|synchronized|async|override|open|suspend|inline|virtual|const|[\w<>[\],?]+)\s+)*(?:(\w+)::)?(~?\w+)\s*\(/.exec(code);
|
|
464
|
+
if (m && !m[1] && !m[2] && declares(code, m.index + m[0].length - 1))
|
|
397
465
|
onValue = true;
|
|
398
|
-
else if (m && !/^(if|for|while|switch|return|catch|new)$/.test(m[1] ?? m[
|
|
399
|
-
fn = m[1] ?? m[
|
|
466
|
+
else if (m && !/^(if|for|while|switch|return|catch|new)$/.test(m[1] ?? m[3])) {
|
|
467
|
+
fn = m[1] ?? m[3];
|
|
400
468
|
fnLine = i;
|
|
469
|
+
if (m[2]) {
|
|
470
|
+
cls = m[2];
|
|
471
|
+
if (fn === m[2] || fn === `~${m[2]}`) {
|
|
472
|
+
fn = undefined;
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
401
476
|
}
|
|
402
477
|
}
|
|
403
478
|
// (a Python function at the module's top level is in no class, whatever precedes it: the def the law sits on, not a
|
|
@@ -428,18 +503,22 @@ export async function checkTarget(t, o) {
|
|
|
428
503
|
const outs = [];
|
|
429
504
|
// (the clock's unit, for durations in a law: the language's clock, or clock = "s" | "ms" in gdp.toml or --clock)
|
|
430
505
|
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];
|
|
431
|
-
const others = Object.fromEntries(rules.filter(r => r.x.ok).map(r => [r.entry ?? r.x.model?.name ?? '', r.x]));
|
|
506
|
+
const others = Object.fromEntries(rules.filter(r => r.x.ok && r.ctor === undefined).map(r => [r.entry ?? r.x.model?.name ?? '', r.x]));
|
|
432
507
|
const cfg = configFor(t.lang === 'go' || t.lang === 'rust' || fs.statSync(t.at).isDirectory() ? t.at : path.dirname(t.at));
|
|
433
|
-
const
|
|
434
|
-
for (const { entry, x: x0 } of rules) {
|
|
508
|
+
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 } : {}) };
|
|
509
|
+
for (const [initializerIndex, { entry, ctor, x: x0 }] of rules.entries()) {
|
|
510
|
+
// Different initial states must never overwrite one another's certificates.
|
|
511
|
+
const ctx = ctor !== undefined && baseCtx.cert ? { ...baseCtx, cert: path.join(baseCtx.cert, `initializer-${initializerIndex}`) } : baseCtx;
|
|
435
512
|
let x = x0;
|
|
436
513
|
const name = entry ?? (x.model?.name || undefined);
|
|
437
514
|
// (a target that is the working directory, a crate's or a package's: `.`)
|
|
438
|
-
const r = { file: path.relative(proc.cwd(), t.at) || '.', lang: LANG_NAME[t.lang], ...(name ? { entry: name } : {}), ok: x.ok, refusals: x.refusals, notes: x.notes, names: x.names ?? [], laws: [], proposed: [], ...(x.source ? { source: x.source } : {}) };
|
|
515
|
+
const r = { file: path.relative(proc.cwd(), t.at) || '.', lang: LANG_NAME[t.lang], ...(name ? { entry: name } : {}), ...(ctor !== undefined ? { ctor } : {}), ok: x.ok, refusals: x.refusals, notes: x.notes, names: x.names ?? [], laws: [], proposed: [], ...(x.source ? { source: x.source } : {}) };
|
|
439
516
|
outs.push(r);
|
|
440
517
|
// (the laws of this rule: all where it is the file's one, else those in its class or on it or its methods, and those
|
|
441
518
|
// outside every class and function)
|
|
442
|
-
|
|
519
|
+
// (and every request, one with no argument too: the method's choice)
|
|
520
|
+
const ev0 = x.model?.inputs?.find(v => v.name === (x.names ?? []).find(n => n.role === 'method')?.rule)?.sort;
|
|
521
|
+
const ms0 = new Set([...(x.names ?? []).map(n => n.method), ...(ev0?.k === 'choice' ? ev0.values ?? [] : [])]);
|
|
443
522
|
// (a law in a class is that class's alone, an entry named or not)
|
|
444
523
|
// (a law on a function outside any class is that function's, where the file has a rule of its name, never a method
|
|
445
524
|
// of another rule that shares the name)
|
|
@@ -463,6 +542,39 @@ export async function checkTarget(t, o) {
|
|
|
463
542
|
const methods = new Set([...(x.names ?? []).filter(n => n.method).map(n => n.method), ...(evSort?.k === 'choice' ? evSort.values : [])]);
|
|
464
543
|
const stated = mine.map(l => ({ ...l, ...(l.fn && methods.has(l.fn) ? { method: l.fn } : {}) }));
|
|
465
544
|
const proven = [];
|
|
545
|
+
// (the environment the code runs in: --env, gdp.toml's env for the rule or every rule, or a `gdp: env` comment in
|
|
546
|
+
// its class: every call at once at its isolation level, keys that expire, retries; its laws lifted to it)
|
|
547
|
+
const words = o.env ?? (name ? cfg.rules[name]?.env : undefined) ?? envTags(t.files, name) ?? cfg.all.env;
|
|
548
|
+
let sys;
|
|
549
|
+
if (words) {
|
|
550
|
+
try {
|
|
551
|
+
const m = x.rule.machine, stores = [...new Set((x.names ?? []).filter(n => n.map?.store && n.rule).map(n => n.rule))].map(b => Object.keys(m.maps ?? {}).filter(k => k === b || k.startsWith(`${b}.`))).filter(c => c.length);
|
|
552
|
+
const own = Object.keys(m.state).filter(k => (x.names ?? []).some(n => (n.role === 'failed' || n.role === 'result') && ((n.rule && (k === n.rule || k.startsWith(`${n.rule}$`))) || k === n.none)));
|
|
553
|
+
const ev = (x.names ?? []).find(n => n.role === 'method'), evSort = x.model?.inputs.find(v => v.name === x.model?.event)?.sort;
|
|
554
|
+
const failedVar = (x.names ?? []).find(n => n.role === 'failed')?.rule;
|
|
555
|
+
// (a flow the laws state where the env doesn't: at most one call between a and b is the flow a then b, a and a a
|
|
556
|
+
// call of a alone, holding once it did its work)
|
|
557
|
+
const env = envOf(words), bw = mine.map(l => /^at\s+most\s+one\s+call\s+between\s+([\w.]+)\s+and\s+([\w.]+)$/i.exec(l.expr.trim())).find(Boolean);
|
|
558
|
+
if (!env.flow && bw)
|
|
559
|
+
env.flow = bw[1] === bw[2] ? [bw[1]] : [bw[1], bw[2]];
|
|
560
|
+
sys = inEnv(x.rule, env, { stores, own, ...(ev && evSort?.k === 'choice' ? { method: { name: ev.rule, values: evSort.values } } : {}), ...(failedVar ? { failed: failedVar } : {}), args: (x.names ?? []).filter(n => n.role === 'input' && n.method && n.rule).map(n => ({ method: n.method, code: n.code, rule: n.rule })),
|
|
561
|
+
oks: [...(x.names ?? []).filter(n => n.role === 'result' && n.method && x.model?.state.find(v => v.name === n.rule)?.sort.k === 'bool').map(n => ({ method: n.method, rule: n.rule })),
|
|
562
|
+
// (a method that makes an effect did its work where it made it: a charge, a handled message)
|
|
563
|
+
...Object.entries(x.read?.effectsOf ?? {}).flatMap(([method, vs]) => vs.map(rule => ({ method, rule })))] });
|
|
564
|
+
r.env = sys.models.map(md => `${md.name}: ${md.assumes}`);
|
|
565
|
+
}
|
|
566
|
+
catch (e) {
|
|
567
|
+
const why = `the environment: ${e.message}`;
|
|
568
|
+
r.laws = mine.map(l => ({ name: l.name, expr: l.expr, where: l.where, verdict: 'not read', why, ms: 0 }));
|
|
569
|
+
// Opt-in security checking must not silently succeed when there are no stated laws
|
|
570
|
+
// and the requested attacker/concurrency model could not be constructed.
|
|
571
|
+
if (o.security) {
|
|
572
|
+
r.ok = false;
|
|
573
|
+
r.refusals.push({ where: t.at, what: why });
|
|
574
|
+
}
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
466
578
|
// (a law is known by its name: a name stated twice in one rule is refused, both times)
|
|
467
579
|
const twice = (l) => stated.filter(m => m.name === l.name).map(m => m.where);
|
|
468
580
|
// (from = "any": every law proven from every state the laws allow, not only those a run from the start reaches, for
|
|
@@ -473,7 +585,7 @@ export async function checkTarget(t, o) {
|
|
|
473
585
|
const kindOf = (l) => { if (isTwoRuns(l.expr))
|
|
474
586
|
return 'two'; if (isLeadsTo(l.expr))
|
|
475
587
|
return 'leads'; try {
|
|
476
|
-
return buildLaw(x, l,
|
|
588
|
+
return buildLaw(x, l, ctx).kind;
|
|
477
589
|
}
|
|
478
590
|
catch {
|
|
479
591
|
return 'bad';
|
|
@@ -482,14 +594,26 @@ export async function checkTarget(t, o) {
|
|
|
482
594
|
const order = [...stated.keys()].sort((a, b) => rank(stated[a]) - rank(stated[b]));
|
|
483
595
|
// (from any state, the laws about states as one inductive set: the largest the stated ones make, each law the
|
|
484
596
|
// kernel's step breaks taken out in turn (Houdini), the others proven together; one taken out is judged alone)
|
|
485
|
-
const inductive = from && x.rule ? houdini(x, stated.filter(m => twice(m).length === 1 && kindOf(m) === 'law'), o.ms, ctx
|
|
597
|
+
const inductive = from && x.rule && !sys ? houdini(x, stated.filter(m => twice(m).length === 1 && kindOf(m) === 'law'), o.ms, ctx) : undefined;
|
|
486
598
|
const outsOf = [];
|
|
487
599
|
for (const i of order) {
|
|
488
600
|
const l = stated[i];
|
|
489
601
|
outsOf[i] = twice(l).length > 1 ? { name: l.name, expr: l.expr, where: l.where, verdict: 'not read', why: `a law of this name is stated twice (${twice(l).join(', ')}): a law is known by its name`, ms: 0 }
|
|
490
|
-
: prove(x, l, o.ms, proven, { ...ctx, entry: name, ...(from ? { from, inductive, together: stated.filter(m => twice(m).length === 1 && kindOf(m) === 'law' && inductive.has(m.name)) } : {}) });
|
|
602
|
+
: sys ? proveInEnv(x, l, o.ms, proven, { ...ctx, sys, entry: name }) : prove(x, l, o.ms, proven, { ...ctx, entry: name, ...(from ? { from, inductive, together: stated.filter(m => twice(m).length === 1 && kindOf(m) === 'law' && inductive.has(m.name)) } : {}) });
|
|
491
603
|
}
|
|
492
604
|
r.laws = outsOf;
|
|
605
|
+
if (o.security) {
|
|
606
|
+
// Deliberately separate from accepted policy and from heuristic proposals that hide broken guesses.
|
|
607
|
+
// Do not pass previously proven candidates as hypotheses; use the same environment/replay as stated laws.
|
|
608
|
+
const candidates = securityTemplates(x), until = Date.now() + o.ms;
|
|
609
|
+
r.security = candidates.map(l => ({ ...(Date.now() >= until
|
|
610
|
+
? { name: l.name, expr: l.expr, verdict: 'unknown', why: 'security proposal budget exhausted', ms: 0 }
|
|
611
|
+
: sys ? proveInEnv(x, l, Math.max(1, Math.min(2000, until - Date.now())), [], { ...ctx, sys, entry: name, cert: undefined })
|
|
612
|
+
: prove(x, l, Math.max(1, Math.min(2000, until - Date.now())), [], { ...ctx, entry: name, cert: undefined })),
|
|
613
|
+
securityKind: l.securityKind, review: l.review,
|
|
614
|
+
where: `${l.method ? `above ${l.method}: ` : ''}${COMMENT[t.lang]} gdp: law ${l.name}: ${l.expr}` }));
|
|
615
|
+
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');
|
|
616
|
+
}
|
|
493
617
|
if (o.propose && x.model) {
|
|
494
618
|
const p = propose(x, t.lang, o, proven, new Set(stated.map(l => l.expr.replace(/\s+/g, ''))));
|
|
495
619
|
r.proposed = p.shown;
|
|
@@ -514,9 +638,9 @@ export async function checkTarget(t, o) {
|
|
|
514
638
|
const CLOCK = { python: 's', elixir: 's', rust: 's', ts: 'ms', java: 'ms', kotlin: 'ms' };
|
|
515
639
|
// The largest set of these laws that is inductive from every state they allow together: each law whose step the
|
|
516
640
|
// kernel breaks taken out, the rest tried again.
|
|
517
|
-
function houdini(x, ls, ms,
|
|
641
|
+
function houdini(x, ls, ms, opts) {
|
|
518
642
|
let set = ls.flatMap(l => { try {
|
|
519
|
-
const b = buildLaw(x, l,
|
|
643
|
+
const b = buildLaw(x, l, opts);
|
|
520
644
|
return b.kind === 'law' ? [{ l, law: b.law }] : [];
|
|
521
645
|
}
|
|
522
646
|
catch {
|
|
@@ -584,7 +708,7 @@ function prove(x0, l, ms, proven, ctx) {
|
|
|
584
708
|
if (isTwoRuns(l.expr))
|
|
585
709
|
two = buildTwoRuns(x, l, ctx?.others);
|
|
586
710
|
else
|
|
587
|
-
b = buildLaw(x, l,
|
|
711
|
+
b = buildLaw(x, l, ctx ?? {});
|
|
588
712
|
}
|
|
589
713
|
catch (e) {
|
|
590
714
|
return { ...base, verdict: 'not read', why: e.message, ms: 0 };
|
|
@@ -607,7 +731,7 @@ function prove(x0, l, ms, proven, ctx) {
|
|
|
607
731
|
}
|
|
608
732
|
// (from any state: a law about states proven with the others stated beside it, as one inductive set)
|
|
609
733
|
const beside = () => (ctx?.together ?? []).filter(m => m.name !== l.name).flatMap(m => { try {
|
|
610
|
-
const y = buildLaw(x, m,
|
|
734
|
+
const y = buildLaw(x, m, ctx ?? {});
|
|
611
735
|
return y.kind === 'law' ? [y.law] : [];
|
|
612
736
|
}
|
|
613
737
|
catch {
|
|
@@ -665,6 +789,104 @@ function prove(x0, l, ms, proven, ctx) {
|
|
|
665
789
|
return { ...base, 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 === '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('; ') } : {}),
|
|
666
790
|
...(v.run && !two ? { assumes: assumedOf(x, v.run) } : {}), ...(found?.length ? { found } : {}), ...(cert ? { cert } : {}), ms: Date.now() - t0 };
|
|
667
791
|
}
|
|
792
|
+
// 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
|
|
793
|
+
// lifted to every call at once; proven of the system, a run shown as the calls' steps.
|
|
794
|
+
function proveInEnv(x, l, ms, proven, ctx) {
|
|
795
|
+
const t0 = Date.now(), sys = ctx.sys, base = { name: l.name, expr: l.expr, ...(l.where ? { where: l.where } : {}) };
|
|
796
|
+
if (isLeadsTo(l.expr) || isTwoRuns(l.expr))
|
|
797
|
+
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 };
|
|
798
|
+
// (at most one call between a and b: a flow's mutual exclusion, its leases running out where their keys expire)
|
|
799
|
+
const bw = /^at\s+most\s+one\s+call\s+between\s+([\w.]+)\s+and\s+([\w.]+)$/i.exec(l.expr.trim());
|
|
800
|
+
let b;
|
|
801
|
+
try {
|
|
802
|
+
b = bw ? { kind: 'law', law: sys.between(l.name, bw[1], bw[2]) } : buildLaw(x, l, ctx);
|
|
803
|
+
}
|
|
804
|
+
catch (e) {
|
|
805
|
+
return { ...base, verdict: 'not read', why: e.message, ms: 0 };
|
|
806
|
+
}
|
|
807
|
+
const inv = (x.invariants ?? []).map(sys.law);
|
|
808
|
+
let v, law;
|
|
809
|
+
try {
|
|
810
|
+
if (b.kind === 'law') {
|
|
811
|
+
law = bw ? b.law : sys.law(b.law);
|
|
812
|
+
v = proveRule(sys.rule, [...inv, law], { search: { ms } });
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
law = sys.step(b.law);
|
|
816
|
+
v = proveSteps(sys.rule, [...inv, ...proven], [law], { search: { ms } });
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
catch (e) {
|
|
820
|
+
return { ...base, kind: b.kind, verdict: 'unknown', why: e.message, ms: Date.now() - t0 };
|
|
821
|
+
}
|
|
822
|
+
// (not proven and no run: calls contending with one request, a run the search's own draws seldom make)
|
|
823
|
+
if (!(v.proven && v.checked) && !v.run) {
|
|
824
|
+
const run = contend(sys, law, { ms: Math.min(ms, 10_000) });
|
|
825
|
+
if (run)
|
|
826
|
+
v = { ...v, run: run };
|
|
827
|
+
}
|
|
828
|
+
const verdict = v.proven && v.checked ? 'proven' : v.run ? 'broken' : 'unknown';
|
|
829
|
+
if (verdict === 'proven' && b.kind === 'law')
|
|
830
|
+
proven.push(law);
|
|
831
|
+
const found = v.found?.laws?.map(f => f.text);
|
|
832
|
+
return { ...base, kind: b.kind, verdict, ...(v.run && verdict === 'broken' ? { run: sysRunOf(x, sys, shrinkRun(sys.rule, law, v.run)) } : {}), ...(verdict === 'unknown' ? { why: v.why ?? v.stuck ?? 'not proven' } : {}), ...(found?.length ? { found } : {}), ms: Date.now() - t0 };
|
|
833
|
+
}
|
|
834
|
+
// A run of the system as each call's steps: a call begins with its request, reads, commits; a store's key expires.
|
|
835
|
+
function sysRunOf(x, sys, run) {
|
|
836
|
+
const pcs = new Map(), done = (sys.commit ?? 0) + 1, out = [];
|
|
837
|
+
const params = Object.keys(run.params).length ? runOf(x, { params: run.params, trace: [] }) : [];
|
|
838
|
+
// (calls numbered in the order they begin; a store by the code's name)
|
|
839
|
+
const ids = new Map(), n = (p) => { if (!ids.has(p))
|
|
840
|
+
ids.set(p, ids.size + 1); return ids.get(p); };
|
|
841
|
+
const store = (map) => (x.names ?? []).find(m => m.rule === map)?.code ?? map;
|
|
842
|
+
for (const q of run.trace) {
|
|
843
|
+
const a = q[sys.act];
|
|
844
|
+
if (!(a === 0 || a === sys.part)) {
|
|
845
|
+
out.push(`a key of the store expires (key #${String(q['key$'])})`);
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
const call = runOf(x, { params: {}, trace: [q] }).at(-1);
|
|
849
|
+
if (!sys.id) {
|
|
850
|
+
out.push(call);
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
const p = q[sys.id], pc = pcs.get(p) ?? 0;
|
|
854
|
+
if (!sys.commit) {
|
|
855
|
+
out.push(`call ${n(p)}: ${call}`);
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
if (pc >= done)
|
|
859
|
+
continue;
|
|
860
|
+
pcs.set(p, pc === 0 ? (sys.level === 'snapshot' || sys.commit === 1 ? sys.commit : 1) : pc === sys.commit && sys.flow ? 0 : pc + 1);
|
|
861
|
+
out.push(pc === 0 ? `call ${n(p)} begins ${call}` : pc === sys.commit ? `call ${n(p)} commits` : `call ${n(p)} reads ${store(sys.reads[pc - 1])}`);
|
|
862
|
+
}
|
|
863
|
+
return [...params, ...out];
|
|
864
|
+
}
|
|
865
|
+
// The environment a `gdp: env <words>` comment states: one in the rule's class (or naming none, the file's).
|
|
866
|
+
const ENV = /(?:#|\/\/|--|%|\/\*|^\s*\*)\s*gdp:\s*env\s+(.+?)\s*(?:\*\/)?\s*$/;
|
|
867
|
+
function envTags(files, name) {
|
|
868
|
+
for (const f of files) {
|
|
869
|
+
const lines = fs.readFileSync(f, 'utf8').split('\n');
|
|
870
|
+
for (const [i, l] of lines.entries()) {
|
|
871
|
+
const m = ENV.exec(l);
|
|
872
|
+
if (!m)
|
|
873
|
+
continue;
|
|
874
|
+
// (a tag right above a class statement is that class's, else the class it is in)
|
|
875
|
+
let cls;
|
|
876
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
877
|
+
if (/^\s*(\/\/|\/?\*|#|@|$)/.test(lines[j]))
|
|
878
|
+
continue;
|
|
879
|
+
cls = classAt(lines[j]);
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
for (let j = i; j >= 0 && !cls; j--)
|
|
883
|
+
cls = classAt(lines[j]);
|
|
884
|
+
if (!cls || !name || cls === name)
|
|
885
|
+
return m[1];
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return undefined;
|
|
889
|
+
}
|
|
668
890
|
// Two runs as calls of the code: each request once, the values the two runs take apart as `a | b`, and the run b leaves
|
|
669
891
|
// out (isolation's: the others' calls) marked.
|
|
670
892
|
function pairRunOf(x, run, two) {
|
|
@@ -705,6 +927,10 @@ function shownValue(x, rule, vars, none) {
|
|
|
705
927
|
// A run as calls of the code: the constructor's arguments, then each request (the method, its arguments by the code's
|
|
706
928
|
// names, the answers and the clock), the last the one that breaks the law.
|
|
707
929
|
export function runOf(x, run) {
|
|
930
|
+
if (x.fibers?.length) {
|
|
931
|
+
const plain = { ...x, fibers: undefined };
|
|
932
|
+
return [...runOf(plain, { params: run.params, trace: [] }), ...fiberRun(x, run, q => runOf(plain, { params: {}, trace: [q] }).at(-1))];
|
|
933
|
+
}
|
|
708
934
|
const names = namesWithClock(x), code = (n) => n.code;
|
|
709
935
|
const ps = names.filter(n => n.role === 'param' && n.rule && n.rule in run.params);
|
|
710
936
|
const lines = ps.length ? [`made with ${ps.map(n => `${code(n)} = ${shownValue(x, n.rule, run.params, n.none)}`).join(', ')}`] : [];
|
|
@@ -796,7 +1022,7 @@ export const proposedLaws = (x, lang, ms = 2000) => propose(x, lang, { ms, propo
|
|
|
796
1022
|
// --- printing ------------------------------------------------------------------------------------------------------------
|
|
797
1023
|
const ROLE = { state: 'state', param: 'made with', input: 'request', answer: 'answered', result: 'result', failed: 'failed', method: 'method', clock: 'clock', const: 'constant' };
|
|
798
1024
|
function printRule(r, o) {
|
|
799
|
-
out(`${r.file}${r.entry ? `: ${r.entry}` : ''} (${r.lang})`);
|
|
1025
|
+
out(`${r.file}${r.entry ? `: ${r.entry}` : ''}${r.ctor !== undefined ? ` [ctor ${r.ctor}]` : ''} (${r.lang})`);
|
|
800
1026
|
if (!r.ok) {
|
|
801
1027
|
for (const f of r.refusals)
|
|
802
1028
|
out(` ${paint('yellow', `refused at ${f.where}:`)} ${f.what}`);
|
|
@@ -804,6 +1030,11 @@ function printRule(r, o) {
|
|
|
804
1030
|
else {
|
|
805
1031
|
if (r.checked)
|
|
806
1032
|
out(` ${paint('dim', r.checked)}`);
|
|
1033
|
+
if (r.env) {
|
|
1034
|
+
out(' in its environment (every call at once; the laws below are about these runs):');
|
|
1035
|
+
for (const e of r.env)
|
|
1036
|
+
out(` ${e}`);
|
|
1037
|
+
}
|
|
807
1038
|
const inferred = r.notes.filter(n => /inferred|tagged|left out|answered|injected|the entry/.test(n));
|
|
808
1039
|
for (const n of inferred.slice(0, 12))
|
|
809
1040
|
out(` ${n}`);
|
|
@@ -839,6 +1070,12 @@ function printRule(r, o) {
|
|
|
839
1070
|
for (const l of r.laws)
|
|
840
1071
|
law(l, false);
|
|
841
1072
|
}
|
|
1073
|
+
if (r.security) {
|
|
1074
|
+
out(' security candidates (NOT accepted policy; review the requirement and authentication boundary):');
|
|
1075
|
+
for (const l of r.security)
|
|
1076
|
+
law(l, true);
|
|
1077
|
+
out(' Candidates do not affect the exit code. State reviewed candidates as gdp: law comments.');
|
|
1078
|
+
}
|
|
842
1079
|
if (r.proposed.length || r.brokenProposed) {
|
|
843
1080
|
out(' laws proposed (nothing written; state one with the comment under it):');
|
|
844
1081
|
for (const l of r.proposed)
|
|
@@ -852,15 +1089,20 @@ function printRule(r, o) {
|
|
|
852
1089
|
out();
|
|
853
1090
|
}
|
|
854
1091
|
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);
|
|
855
|
-
const USAGE = `gdp-wired check <file|dir>... [--entry X] [--methods a,b] [--failures kept] [--on-error discard] [--json] [--ms 10000] [--no-propose] [--clock s|ms] [--cert <dir>] [--from any]
|
|
1092
|
+
const USAGE = `gdp-wired check <file|dir>... [--entry X] [--methods a,b] [--failures kept] [--on-error discard] [--json] [--ms 10000] [--no-propose] [--clock s|ms] [--cert <dir>] [--from any] [--require-review] [--security]
|
|
1093
|
+
gdp-wired draft <file> --clause <text> | --clause-file <file> --cite <ref> [--llm <command> | --answer <file>] [--by <who>]
|
|
856
1094
|
|
|
857
1095
|
Reads the rule in each file (Python, Ruby, Elixir, Java, Kotlin, Go, Rust, Swift, C, C++, TypeScript, Effect, XState), checks it
|
|
858
1096
|
against the code by running both, proves the laws stated in the code (\`# gdp: law <name>: <expr>\`, \`// gdp: law ...\`,
|
|
859
1097
|
@GdpLaw("<name>: <expr>")) and proposes others. Laws about two runs: \`<secret> never reaches <fields>\`, \`isolated by <argument>\`,
|
|
860
|
-
\`agrees with <Class>\`; a duration over the clock: \`now - t < 30 days
|
|
1098
|
+
\`agrees with <Class>\`; a duration over the clock: \`now - t < 30 days\`, \`now - t <= 10 business days\` (the calendar: [calendar] in gdp.toml);
|
|
1099
|
+
the clause a law answers: \`gdp: cite <law name>: <clause>\` (drafted from the clause's text by \`draft\`, marked unreviewed until a person signs it);
|
|
861
1100
|
--cert <dir> writes each proven law's certificate (its meta the citations); --from any (or from = "any" in gdp.toml, for every
|
|
862
1101
|
rule or one) proves every law from every state the laws allow, for code that steps the rule from states it is handed. Exit code: 1 when a stated law is broken, 2 when
|
|
863
|
-
one couldn't be checked
|
|
1102
|
+
one couldn't be checked.
|
|
1103
|
+
--security proposes authorization, tenant-write isolation, workflow, quota and ledger candidates over the code's names.
|
|
1104
|
+
Candidates require policy review, show broken runs too, and do not affect the exit code. Arbitrary input identities are
|
|
1105
|
+
not authenticated identities. State the intended policy with gdp: law comments; use gdp: env for concurrent isolation.`;
|
|
864
1106
|
// Every target's rules and their laws, and the exit code (1: a stated law broken; 2: one not checked).
|
|
865
1107
|
export async function check(targets, given = {}, each) {
|
|
866
1108
|
const o = { ms: 10_000, propose: true, ...given }, all = [];
|
|
@@ -872,22 +1114,76 @@ export async function check(targets, given = {}, each) {
|
|
|
872
1114
|
rs.forEach(each);
|
|
873
1115
|
}
|
|
874
1116
|
const stated = all.flatMap(r => r.laws);
|
|
875
|
-
return { rules: all, exit: stated.some(l => l.verdict === 'broken') ? 1 : stated.some(l => l.verdict === 'not read') ? 2 : 0 };
|
|
1117
|
+
return { rules: all, exit: stated.some(l => l.verdict === 'broken') ? 1 : stated.some(l => l.verdict === 'not read') || o.security && all.some(r => !r.ok) ? 2 : 0 };
|
|
1118
|
+
}
|
|
1119
|
+
// --- draft: laws from a clause, for a person to review ----------------------------------------------------------------
|
|
1120
|
+
// gdp-wired draft <file> --clause <text> | --clause-file <f> --cite <ref> [--llm <command> | --answer <file>] [--by <who>]:
|
|
1121
|
+
// the question (core/draft.ts) printed, or asked of the command (on its stdin) or read from an answer, each law it
|
|
1122
|
+
// proposes read over the code's names, the comments to paste printed with where they go.
|
|
1123
|
+
async function draft(target, o) {
|
|
1124
|
+
const { draftComments, draftPrompt, parseDraft, vetDrafts } = await import("./draft.js");
|
|
1125
|
+
const clause = o.clause ?? (o.clauseFile ? fs.readFileSync(o.clauseFile, 'utf8') : undefined), cite = o.cite ?? 'the clause';
|
|
1126
|
+
if (!clause) {
|
|
1127
|
+
out('gdp-wired draft: --clause <text> or --clause-file <file>');
|
|
1128
|
+
return 2;
|
|
1129
|
+
}
|
|
1130
|
+
const t = targetsOf(target)[0], rules = await rulesOf(t, { ...o, propose: false }, []), x = rules.find(r => r.x.ok)?.x;
|
|
1131
|
+
if (!x) {
|
|
1132
|
+
out(`gdp-wired draft: no rule read from ${target}: ${rules[0]?.x.refusals[0]?.what ?? ''}`);
|
|
1133
|
+
return 2;
|
|
1134
|
+
}
|
|
1135
|
+
const prompt = draftPrompt(x, clause, cite);
|
|
1136
|
+
let answer;
|
|
1137
|
+
if (o.answer)
|
|
1138
|
+
answer = fs.readFileSync(o.answer, 'utf8');
|
|
1139
|
+
else if (o.llm) {
|
|
1140
|
+
const { spawnSync } = proc.getBuiltinModule('node:child_process');
|
|
1141
|
+
const p = spawnSync('sh', ['-c', o.llm], { input: prompt, encoding: 'utf8', maxBuffer: 1 << 26 });
|
|
1142
|
+
if (p.status !== 0) {
|
|
1143
|
+
out(`gdp-wired draft: ${o.llm} exited ${p.status}`);
|
|
1144
|
+
return 2;
|
|
1145
|
+
}
|
|
1146
|
+
answer = p.stdout;
|
|
1147
|
+
}
|
|
1148
|
+
else {
|
|
1149
|
+
out(prompt);
|
|
1150
|
+
return 0;
|
|
1151
|
+
}
|
|
1152
|
+
const cfg = configFor(t.lang === 'go' || t.lang === 'rust' || fs.statSync(t.at).isDirectory() ? t.at : path.dirname(t.at)), unit = o.clock ?? cfg.all.clock ?? CLOCK[t.lang];
|
|
1153
|
+
const { kept, refused } = vetDrafts(x, parseDraft(answer), { clock: unit === 's' ? 1 : unit === 'ms' ? 1000 : undefined, ...(cfg.all.calendar ? { calendar: cfg.all.calendar } : {}) });
|
|
1154
|
+
const by = o.by ?? (o.llm ? o.llm.split(/\s+/)[0] : 'an answer given'), c = COMMENT[t.lang];
|
|
1155
|
+
out(`${kept.length} laws drafted from ${cite}, each to be reviewed by a person (then [reviewed-by: <name>, <date>] in place of [unreviewed ...]):`);
|
|
1156
|
+
for (const d of kept) {
|
|
1157
|
+
out(`\n ${d.method ? `on the line above ${d.method}` : 'in the class (a law of every state)'}:`);
|
|
1158
|
+
for (const l of draftComments(c, d, cite, by))
|
|
1159
|
+
out(` ${l}`);
|
|
1160
|
+
}
|
|
1161
|
+
for (const r of refused)
|
|
1162
|
+
out(`\n refused: ${r.d.name}: ${r.d.expr}\n ${r.why}`);
|
|
1163
|
+
return kept.length ? 0 : 2;
|
|
876
1164
|
}
|
|
1165
|
+
// Every target's rules and their laws, and the exit code (1: a stated law broken; 2: one not checked, or with
|
|
1166
|
+
// --require-review, one cited unreviewed).
|
|
877
1167
|
export async function main(argv) {
|
|
878
1168
|
const { cmd, targets, o } = args(argv);
|
|
1169
|
+
if (cmd === 'draft' && targets.length === 1)
|
|
1170
|
+
return draft(targets[0], o);
|
|
879
1171
|
if (cmd !== 'check' || !targets.length) {
|
|
880
1172
|
out(USAGE);
|
|
881
1173
|
return cmd === 'help' || cmd === '--help' || cmd === '-h' || !cmd ? 0 : 2;
|
|
882
1174
|
}
|
|
883
1175
|
tint = colors(proc.env, !!proc.stdout.isTTY, !!o.json);
|
|
884
|
-
const { rules: all, exit:
|
|
1176
|
+
const { rules: all, exit: code0 } = await check(targets, o, o.json ? undefined : r => printRule(r, o));
|
|
885
1177
|
const stated = all.flatMap(r => r.laws);
|
|
1178
|
+
const { reviewOf } = await import("./draft.js"), unreviewed = stated.filter(l => (l.cites ?? []).some(c => reviewOf(c) === 'unreviewed'));
|
|
1179
|
+
const code = code0 === 0 && o.requireReview && unreviewed.length ? 2 : code0;
|
|
886
1180
|
if (o.json)
|
|
887
1181
|
out(JSON.stringify({ rules: all.map(({ source: _s, ...r }) => r), exit: code }, null, 1));
|
|
888
1182
|
else if (stated.length) {
|
|
889
1183
|
const n = (v) => stated.filter(l => l.verdict === v).length;
|
|
890
1184
|
out(`${paint('green', n('proven'))} of ${stated.length} stated laws proven, ${paint('red', n('broken'))} broken, ${paint('yellow', n('unknown'))} unknown, ${paint('yellow', n('not read'))} not read`);
|
|
1185
|
+
if (unreviewed.length)
|
|
1186
|
+
out(`${paint('yellow', unreviewed.length)} cited unreviewed (drafted, no person's sign-off yet: [reviewed-by: <name>, <date>])${o.requireReview ? ': refused by --require-review' : ''}: ${unreviewed.map(l => l.name).join('; ')}`);
|
|
891
1187
|
}
|
|
892
1188
|
return code;
|
|
893
1189
|
}
|
package/dist/core/compose.js
CHANGED
|
@@ -25,7 +25,9 @@ function rename(e, prefix, m, inputs) {
|
|
|
25
25
|
case 'sub':
|
|
26
26
|
case 'min':
|
|
27
27
|
case 'max':
|
|
28
|
-
case 'prod':
|
|
28
|
+
case 'prod':
|
|
29
|
+
case 'tup': return { ...e, a: rename(e.a, prefix, m, inputs), b: rename(e.b, prefix, m, inputs) };
|
|
30
|
+
case 'proj': return { ...e, a: rename(e.a, prefix, m, inputs) };
|
|
29
31
|
default: return unreachable(e);
|
|
30
32
|
}
|
|
31
33
|
}
|
package/dist/core/counts.d.ts
CHANGED
|
@@ -15,11 +15,14 @@ export declare function certFor(goal: {
|
|
|
15
15
|
map: string;
|
|
16
16
|
below: E;
|
|
17
17
|
j: string;
|
|
18
|
+
key: string;
|
|
18
19
|
body: E;
|
|
19
|
-
}[]): {
|
|
20
|
+
}[], wide?: boolean, most?: number): {
|
|
20
21
|
reads: MapRead[];
|
|
21
22
|
insts: CountInst[];
|
|
22
23
|
wits: string[];
|
|
24
|
+
picks: [string, E[]][];
|
|
25
|
+
loose: boolean;
|
|
23
26
|
};
|
|
24
27
|
export declare function candidates(src: Parameters<typeof inferLaws>[0], m: Machine, caller: Law[], shapes: Law[], guarded: Law[], ms: number, until: number): Law[];
|
|
25
28
|
export type Tried<P> = {
|
|
@@ -27,7 +30,7 @@ export type Tried<P> = {
|
|
|
27
30
|
} | {
|
|
28
31
|
stuck: string;
|
|
29
32
|
};
|
|
30
|
-
export declare function cone<P>(m: Machine, set: Law[], attempt: (law: Law, ls: Law[], ms: number) => Tried<P>, until: number): Map<string, P>;
|
|
33
|
+
export declare function cone<P>(m: Machine, set: Law[], attempt: (law: Law, ls: Law[], ms: number) => Tried<P>, until: number, houdini?: boolean): Map<string, P>;
|
|
31
34
|
export type Counted = {
|
|
32
35
|
proven: boolean;
|
|
33
36
|
laws: Law[];
|