gdp-wired 0.45.0 → 0.47.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 +61 -8
- 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 +423 -31
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/cli.d.ts +4 -0
- package/dist/core/cli.js +206 -40
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +4 -1
- package/dist/core/counts.js +314 -85
- 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 +2 -1
- package/dist/core/data.js +223 -24
- 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 +37 -3
- package/dist/core/dsl.js +167 -26
- package/dist/core/effect-schema.d.ts +90 -0
- package/dist/core/effect-schema.js +500 -0
- package/dist/core/effect.d.ts +4 -11
- package/dist/core/effect.js +3 -79
- package/dist/core/exists.d.ts +1 -0
- package/dist/core/exists.js +191 -16
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +169 -22
- package/dist/core/extract-check.d.ts +1 -0
- package/dist/core/extract-check.js +97 -6
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +26 -5
- package/dist/core/extract-go.d.ts +8 -0
- package/dist/core/extract-go.js +67 -6
- 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 +2 -0
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +20 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +1 -1
- package/dist/core/extract-read.d.ts +26 -1
- package/dist/core/extract-read.js +14 -7
- package/dist/core/extract-rs.js +63 -15
- package/dist/core/extract-shapes.d.ts +1 -0
- package/dist/core/extract-shapes.js +84 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +70 -22
- package/dist/core/extract-standalone.d.ts +3 -0
- package/dist/core/extract-standalone.js +221 -0
- package/dist/core/extract-step.d.ts +151 -1
- package/dist/core/extract-step.js +1232 -60
- package/dist/core/extract-swift.js +6 -2
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/extract.js +77 -7
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +918 -217
- package/dist/core/jvm/JavaReader.java +23 -6
- package/dist/core/jvm/Jvm.java +3 -0
- package/dist/core/jvm/KtReader.java +6 -5
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +226 -23
- package/dist/core/machine.d.ts +15 -1
- package/dist/core/machine.js +187 -15
- 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 +183 -10
- package/dist/core/py/reader.py +234 -40
- 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/Cargo.toml +1 -1
- package/dist/core/rs/src/main.rs +466 -11
- 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 +57 -4
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +3 -1
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.js +1 -1
- package/dist/core/transfer.js +22 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +50 -5
- package/dist/interchange/format.js +11 -1
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +56 -9
- package/dist/kernel/epr.js +108 -26
- package/dist/kernel/kernel.d.ts +29 -1
- package/dist/kernel/kernel.js +325 -62
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +10 -3
- package/dist/kernel/prove.js +332 -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.js +30 -37
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +6 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Cond, Int, type IntLike, Term } from './dsl.js';
|
|
2
|
+
export type Calendar = {
|
|
3
|
+
weekend?: string[];
|
|
4
|
+
holidays?: string[];
|
|
5
|
+
utc_offset?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class CalendarError extends Error {
|
|
8
|
+
}
|
|
9
|
+
export type Pinned = {
|
|
10
|
+
t: Int;
|
|
11
|
+
w: Int;
|
|
12
|
+
};
|
|
13
|
+
export declare function businessDays(cal: Calendar, clock?: 's' | 'ms'): {
|
|
14
|
+
calendar: {
|
|
15
|
+
weekend: string[];
|
|
16
|
+
holidays: number;
|
|
17
|
+
offset: string;
|
|
18
|
+
clock: "s" | "ms";
|
|
19
|
+
};
|
|
20
|
+
upTo: (x: IntLike | Pinned) => Int;
|
|
21
|
+
between: (a: IntLike | Pinned, b: IntLike | Pinned) => Int;
|
|
22
|
+
pin: (x: IntLike, w: IntLike) => {
|
|
23
|
+
at: Pinned;
|
|
24
|
+
guard: Cond;
|
|
25
|
+
};
|
|
26
|
+
count: (a: number, b: number) => number;
|
|
27
|
+
};
|
|
28
|
+
export type BusinessDays = ReturnType<typeof businessDays>;
|
|
29
|
+
export declare const keyInt: (k: Term, k2?: Term) => Int;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Business days over a calendar (`gdp-wired/laws`): "within 10 business days" decided in the kernel's own arithmetic,
|
|
2
|
+
// nothing new trusted. A calendar is its weekend days, its holidays (dates) and its offset from UTC, stated once
|
|
3
|
+
// (`[calendar]` in gdp.toml, or given here); the request's time is the clock's (seconds or milliseconds since 1970 UTC).
|
|
4
|
+
//
|
|
5
|
+
// The count. A time x is on day s(x) = ⌊(x + offset)/D⌋ + 10 (D a day in the clock's units; day 0 the Monday 1969-12-22,
|
|
6
|
+
// so a time from 1970 on, at any offset within ±14 h, is on a day at least 0). C(x), the business days up to and
|
|
7
|
+
// including x's day, is
|
|
8
|
+
// C(x) = k·w + #{p a working weekday : p <= r} − #{h a holiday on a working weekday : h <= s(x)}
|
|
9
|
+
// with w = ⌊y/7D⌋ x's week, r its weekday (0 Monday), y = x + offset + 10·D and k the working days in a week. Each
|
|
10
|
+
// "p <= r" is y >= 7D·w + D·p, and each "h <= s(x)" is y >= D·h: comparisons linear in y and w. So C is linear but for
|
|
11
|
+
// the one division ⌊y/7D⌋. Where the law may read functions (a law about every state) that is divBy(7D), the kernel's
|
|
12
|
+
// own div$k with its facts; a law of one step can't read a function, so there the week is a key the law holds at
|
|
13
|
+
// every value of, under the guard 7D·w <= y < 7D·w + 7D, which only ⌊y/7D⌋ meets: ∀w. guard → L is L at ⌊y/7D⌋.
|
|
14
|
+
//
|
|
15
|
+
// Elapsed business days from a to b: C(b) − C(a), the business days after a's day up to and including b's (the day
|
|
16
|
+
// of receipt doesn't count; the last day counts whole). Negative where b is before a. `now - received <= 10 business
|
|
17
|
+
// days` in a law is C(now) − C(received) <= 10.
|
|
18
|
+
//
|
|
19
|
+
// What it doesn't model: daylight saving (one fixed offset), a holiday not listed (a year with no list has none),
|
|
20
|
+
// half days. The calendar is the person's statement, like a law's citation; the arithmetic over it is exact.
|
|
21
|
+
import { Int, all, when } from "./dsl.js";
|
|
22
|
+
const DAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
|
23
|
+
export class CalendarError extends Error {
|
|
24
|
+
}
|
|
25
|
+
// Day index of a date (YYYY-MM-DD) from the Monday 1969-12-22.
|
|
26
|
+
const dayOf = (d) => {
|
|
27
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(d.trim());
|
|
28
|
+
const t = m ? Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])) : NaN;
|
|
29
|
+
if (!m || Number.isNaN(t) || new Date(t).toISOString().slice(0, 10) !== d.trim())
|
|
30
|
+
throw new CalendarError(`${d}: a holiday is a date, YYYY-MM-DD`);
|
|
31
|
+
return t / 86_400_000 + 10;
|
|
32
|
+
};
|
|
33
|
+
export function businessDays(cal, clock = 's') {
|
|
34
|
+
const unit = clock === 'ms' ? 1000 : 1, D = 86_400 * unit, W = 7 * D;
|
|
35
|
+
const weekend = (cal.weekend ?? ['sat', 'sun']).map(d => d.trim().toLowerCase().slice(0, 3));
|
|
36
|
+
for (const d of weekend)
|
|
37
|
+
if (!DAYS.includes(d))
|
|
38
|
+
throw new CalendarError(`${d}: a weekend day is one of ${DAYS.join(', ')}`);
|
|
39
|
+
const work = DAYS.map((_, p) => p).filter(p => !weekend.includes(DAYS[p]));
|
|
40
|
+
if (!work.length)
|
|
41
|
+
throw new CalendarError('a calendar whose every day is a weekend day has no business day');
|
|
42
|
+
const off = /^([+-])(\d{2}):(\d{2})$/.exec((cal.utc_offset ?? '+00:00').trim());
|
|
43
|
+
if (!off || Number(off[2]) * 60 + Number(off[3]) > 14 * 60 || Number(off[3]) > 59)
|
|
44
|
+
throw new CalendarError(`${cal.utc_offset}: an offset from UTC is ±HH:MM, at most 14 hours`);
|
|
45
|
+
const offset = (off[1] === '-' ? -1 : 1) * (Number(off[2]) * 3600 + Number(off[3]) * 60) * unit;
|
|
46
|
+
// (the holidays that take a working day away, each once, in order)
|
|
47
|
+
const hols = [...new Set((cal.holidays ?? []).map(dayOf))].filter(h => work.includes(((h % 7) + 7) % 7)).sort((a, b) => a - b);
|
|
48
|
+
const shift = (x) => Int.of(x).plus(offset + 10 * D);
|
|
49
|
+
// (the holidays on or before y's day, as a balanced choice: one path per count, never 2^n)
|
|
50
|
+
const held = (y, lo, hi) => {
|
|
51
|
+
if (lo > hi)
|
|
52
|
+
return Int.of(0);
|
|
53
|
+
const mid = (lo + hi) >> 1;
|
|
54
|
+
return when(y.atLeast(hols[mid] * D), held(y, mid + 1, hi).plus(mid - lo + 1), held(y, lo, mid - 1));
|
|
55
|
+
};
|
|
56
|
+
// C at y = x + offset + 10D in week w.
|
|
57
|
+
const count = (y, w) => work.reduce((n, p) => n.plus(when(y.atLeast(w.times(W).plus(p * D)), Int.of(1), Int.of(0))), w.times(work.length)).minus(held(y, 0, hols.length - 1));
|
|
58
|
+
const pinned = (x) => typeof x === 'object' && x !== null && 'w' in x && 't' in x;
|
|
59
|
+
const C = (x) => (pinned(x) ? count(shift(x.t), x.w) : count(shift(x), shift(x).divBy(W)));
|
|
60
|
+
return {
|
|
61
|
+
calendar: { weekend, holidays: hols.length, offset: cal.utc_offset ?? '+00:00', clock },
|
|
62
|
+
// The business days up to and including x's day (from 1969-12-22), and from a's day to b's.
|
|
63
|
+
upTo: C,
|
|
64
|
+
between: (a, b) => C(b).minus(C(a)),
|
|
65
|
+
// x's week pinned to the key w (a step law's), with the guard only ⌊y/7D⌋ meets.
|
|
66
|
+
pin: (x, w) => {
|
|
67
|
+
const y = shift(x), wk = Int.of(w);
|
|
68
|
+
return { at: { t: Int.of(x), w: wk }, guard: all(wk.times(W).atMost(y), y.lt(wk.times(W).plus(W))) };
|
|
69
|
+
},
|
|
70
|
+
// The same count computed (for runs and tests): the business days from a's day to b's.
|
|
71
|
+
count: (a, b) => {
|
|
72
|
+
const c = (x) => {
|
|
73
|
+
const y = x + offset + 10 * D, s = Math.floor(y / D), w = Math.floor(y / W), r = s - 7 * w;
|
|
74
|
+
return w * work.length + work.filter(p => p <= r).length - hols.filter(h => h <= s).length;
|
|
75
|
+
};
|
|
76
|
+
return c(b) - c(a);
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// A key's term as an integer (a step law's key is a natural; the week of a time before 1969-12-22 has none, so a key
|
|
81
|
+
// for one is the difference of two).
|
|
82
|
+
export const keyInt = (k, k2) => (k2 ? new Int(k, k2) : Int.of(k));
|
package/dist/core/cli.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import type { Extraction, Name } from './extract.js';
|
|
3
|
+
import { type SecurityCandidate } from './security.js';
|
|
3
4
|
import { type Verdict } from './dsl.js';
|
|
4
5
|
import { type LawText } from './laws.js';
|
|
5
6
|
export declare const colors: (env: Record<string, string | undefined>, tty: boolean, json?: boolean) => boolean;
|
|
6
7
|
export type Opts = {
|
|
7
8
|
entry?: string;
|
|
9
|
+
mode?: 'standalone';
|
|
8
10
|
methods?: string[];
|
|
9
11
|
failures?: 'refuse' | 'kept';
|
|
10
12
|
onError?: 'refuse' | 'discard';
|
|
@@ -52,6 +54,7 @@ export type RuleOut = {
|
|
|
52
54
|
file: string;
|
|
53
55
|
lang: string;
|
|
54
56
|
entry?: string;
|
|
57
|
+
ctor?: string;
|
|
55
58
|
ok: boolean;
|
|
56
59
|
refusals: {
|
|
57
60
|
where: string;
|
|
@@ -65,6 +68,7 @@ export type RuleOut = {
|
|
|
65
68
|
proposed: LawOut[];
|
|
66
69
|
brokenProposed?: number;
|
|
67
70
|
source?: string;
|
|
71
|
+
security?: (LawOut & Pick<SecurityCandidate, 'securityKind' | 'review'>)[];
|
|
68
72
|
};
|
|
69
73
|
type Scoped = LawText & {
|
|
70
74
|
cls?: string;
|
package/dist/core/cli.js
CHANGED
|
@@ -7,6 +7,8 @@ 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";
|
|
@@ -30,6 +32,10 @@ function args(argv) {
|
|
|
30
32
|
o.json = true;
|
|
31
33
|
else if (a === '--no-propose')
|
|
32
34
|
o.propose = false;
|
|
35
|
+
else if (a === '--security')
|
|
36
|
+
o.security = true;
|
|
37
|
+
else if (a === '--require-review')
|
|
38
|
+
o.requireReview = true;
|
|
33
39
|
else if (a.startsWith('--')) {
|
|
34
40
|
const [k, inline] = a.slice(2).split('='), v = inline ?? argv[++i] ?? '';
|
|
35
41
|
const key = k.replace(/-(\w)/g, (_, c) => c.toUpperCase());
|
|
@@ -94,6 +100,25 @@ async function extractOne(t, o) {
|
|
|
94
100
|
throw e;
|
|
95
101
|
}
|
|
96
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
|
+
}
|
|
97
122
|
async function extractWith(t, o) {
|
|
98
123
|
const f = t.at, dir = path.dirname(f);
|
|
99
124
|
switch (t.lang) {
|
|
@@ -151,16 +176,16 @@ async function extractWith(t, o) {
|
|
|
151
176
|
catch {
|
|
152
177
|
return undefined;
|
|
153
178
|
} };
|
|
154
|
-
if (/from\s+['"]effect(\/\w+)?['"]/.test(code)) {
|
|
179
|
+
if (o.mode === undefined && /from\s+['"]effect(\/\w+)?['"]/.test(code)) {
|
|
155
180
|
const { extractEffect } = await import("./effect.js"), effect = await own('effect');
|
|
156
181
|
return extractEffect(file, { ...(effect ? { effect } : {}), ...o });
|
|
157
182
|
}
|
|
158
|
-
if (/from\s+['"]xstate['"]/.test(code) && /\bcreateMachine\b/.test(code)) {
|
|
183
|
+
if (o.mode === undefined && /from\s+['"]xstate['"]/.test(code) && /\bcreateMachine\b/.test(code)) {
|
|
159
184
|
const { extractXState } = await import("./extract-xstate.js"), xstate = await own('xstate');
|
|
160
185
|
return extractXState(file, { ...(xstate ? { xstate } : {}), ...o });
|
|
161
186
|
}
|
|
162
|
-
const { extract } = await import("./extract.js");
|
|
163
|
-
return extract(file, o);
|
|
187
|
+
const { extract } = await import("./extract.js"), files = relativeImports(f);
|
|
188
|
+
return extract(file, { ...(Object.keys(files).length ? { files } : {}), ...o });
|
|
164
189
|
}
|
|
165
190
|
}
|
|
166
191
|
}
|
|
@@ -253,18 +278,58 @@ const merge = (a, b) => {
|
|
|
253
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;
|
|
254
279
|
return out;
|
|
255
280
|
};
|
|
256
|
-
//
|
|
257
|
-
//
|
|
258
|
-
|
|
259
|
-
|
|
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
|
+
}
|
|
260
323
|
async function rulesOf(t, o, laws) {
|
|
261
324
|
const got = await rulesOf0(t, o, laws);
|
|
262
325
|
if (o.entry)
|
|
263
|
-
return got;
|
|
264
|
-
|
|
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)));
|
|
265
330
|
const more = [...new Set(laws.map(l => l.cls ?? l.fn).filter((n) => !!n && !have.has(n)))];
|
|
266
331
|
if (!more.length)
|
|
267
|
-
return got;
|
|
332
|
+
return expandInitializers(t, o, laws, got);
|
|
268
333
|
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
|
|
269
334
|
void _j;
|
|
270
335
|
void _m;
|
|
@@ -273,13 +338,13 @@ async function rulesOf(t, o, laws) {
|
|
|
273
338
|
void _t;
|
|
274
339
|
void _fr;
|
|
275
340
|
const cfg = configFor(t.lang === 'go' || t.lang === 'rust' || fs.statSync(t.at).isDirectory() ? t.at : path.dirname(t.at));
|
|
276
|
-
const { clock: _k, from: _f, env: _v, ...shared } = cfg.all;
|
|
341
|
+
const { clock: _k, from: _f, env: _v, calendar: _cal, ...shared } = cfg.all;
|
|
277
342
|
void _k;
|
|
278
343
|
void _f;
|
|
279
|
-
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])))];
|
|
280
345
|
const extra = await Promise.all(more.map(async (entry) => ({ entry, x: await extractOne(t, { ...merge(merge({ ...shared, keep }, cfg.rules[entry] || {}), flags), entry }) })));
|
|
281
346
|
// (the first rule, read with no entry named, kept only where it read something or nothing else was)
|
|
282
|
-
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]);
|
|
283
348
|
}
|
|
284
349
|
async function rulesOf0(t, o, laws) {
|
|
285
350
|
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
|
|
@@ -292,11 +357,11 @@ async function rulesOf0(t, o, laws) {
|
|
|
292
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
|
|
293
358
|
// read again where gdp.toml has options of its own for it)
|
|
294
359
|
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, ...shared } = cfg.all;
|
|
360
|
+
const { clock: _k, from: _f, env: _v, calendar: _cal, ...shared } = cfg.all;
|
|
296
361
|
void _f;
|
|
297
362
|
void _k;
|
|
298
363
|
// (the names the laws read, so an argument a law reads stays in the rule though the code ignores it)
|
|
299
|
-
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])))];
|
|
300
365
|
const optsFor = (entry) => merge(merge({ ...shared, keep }, (entry && cfg.rules[entry]) || {}), flags);
|
|
301
366
|
const one = async (entry) => {
|
|
302
367
|
const x = await extractOne(t, { ...optsFor(entry), ...(entry ? { entry } : {}) }), found = x.model?.name;
|
|
@@ -308,7 +373,9 @@ async function rulesOf0(t, o, laws) {
|
|
|
308
373
|
if (t.lang === 'ts' || t.lang === 'cpp') {
|
|
309
374
|
const code = t.files.map(f => fs.readFileSync(f, 'utf8')).join('\n');
|
|
310
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;
|
|
311
|
-
|
|
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])];
|
|
312
379
|
const all = await Promise.all(cands.map(c => one(c)));
|
|
313
380
|
const good = all.filter(r => r.x.ok);
|
|
314
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: [] } }];
|
|
@@ -393,12 +460,19 @@ export function scoped(file) {
|
|
|
393
460
|
const code = i === l.line - 1 ? lines[i].replace(/(#|\/\/|--).*$/, '') : lines[i];
|
|
394
461
|
if (i >= l.line && classAt(code))
|
|
395
462
|
break;
|
|
396
|
-
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);
|
|
397
|
-
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))
|
|
398
465
|
onValue = true;
|
|
399
|
-
else if (m && !/^(if|for|while|switch|return|catch|new)$/.test(m[1] ?? m[
|
|
400
|
-
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];
|
|
401
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
|
+
}
|
|
402
476
|
}
|
|
403
477
|
}
|
|
404
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
|
|
@@ -429,18 +503,22 @@ export async function checkTarget(t, o) {
|
|
|
429
503
|
const outs = [];
|
|
430
504
|
// (the clock's unit, for durations in a law: the language's clock, or clock = "s" | "ms" in gdp.toml or --clock)
|
|
431
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];
|
|
432
|
-
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]));
|
|
433
507
|
const cfg = configFor(t.lang === 'go' || t.lang === 'rust' || fs.statSync(t.at).isDirectory() ? t.at : path.dirname(t.at));
|
|
434
|
-
const
|
|
435
|
-
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;
|
|
436
512
|
let x = x0;
|
|
437
513
|
const name = entry ?? (x.model?.name || undefined);
|
|
438
514
|
// (a target that is the working directory, a crate's or a package's: `.`)
|
|
439
|
-
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 } : {}) };
|
|
440
516
|
outs.push(r);
|
|
441
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
|
|
442
518
|
// outside every class and function)
|
|
443
|
-
|
|
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 ?? [] : [])]);
|
|
444
522
|
// (a law in a class is that class's alone, an entry named or not)
|
|
445
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
|
|
446
524
|
// of another rule that shares the name)
|
|
@@ -486,7 +564,14 @@ export async function checkTarget(t, o) {
|
|
|
486
564
|
r.env = sys.models.map(md => `${md.name}: ${md.assumes}`);
|
|
487
565
|
}
|
|
488
566
|
catch (e) {
|
|
489
|
-
|
|
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
|
+
}
|
|
490
575
|
continue;
|
|
491
576
|
}
|
|
492
577
|
}
|
|
@@ -500,7 +585,7 @@ export async function checkTarget(t, o) {
|
|
|
500
585
|
const kindOf = (l) => { if (isTwoRuns(l.expr))
|
|
501
586
|
return 'two'; if (isLeadsTo(l.expr))
|
|
502
587
|
return 'leads'; try {
|
|
503
|
-
return buildLaw(x, l,
|
|
588
|
+
return buildLaw(x, l, ctx).kind;
|
|
504
589
|
}
|
|
505
590
|
catch {
|
|
506
591
|
return 'bad';
|
|
@@ -509,7 +594,7 @@ export async function checkTarget(t, o) {
|
|
|
509
594
|
const order = [...stated.keys()].sort((a, b) => rank(stated[a]) - rank(stated[b]));
|
|
510
595
|
// (from any state, the laws about states as one inductive set: the largest the stated ones make, each law the
|
|
511
596
|
// kernel's step breaks taken out in turn (Houdini), the others proven together; one taken out is judged alone)
|
|
512
|
-
const inductive = from && x.rule && !sys ? 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;
|
|
513
598
|
const outsOf = [];
|
|
514
599
|
for (const i of order) {
|
|
515
600
|
const l = stated[i];
|
|
@@ -517,6 +602,18 @@ export async function checkTarget(t, o) {
|
|
|
517
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)) } : {}) });
|
|
518
603
|
}
|
|
519
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
|
+
}
|
|
520
617
|
if (o.propose && x.model) {
|
|
521
618
|
const p = propose(x, t.lang, o, proven, new Set(stated.map(l => l.expr.replace(/\s+/g, ''))));
|
|
522
619
|
r.proposed = p.shown;
|
|
@@ -541,9 +638,9 @@ export async function checkTarget(t, o) {
|
|
|
541
638
|
const CLOCK = { python: 's', elixir: 's', rust: 's', ts: 'ms', java: 'ms', kotlin: 'ms' };
|
|
542
639
|
// The largest set of these laws that is inductive from every state they allow together: each law whose step the
|
|
543
640
|
// kernel breaks taken out, the rest tried again.
|
|
544
|
-
function houdini(x, ls, ms,
|
|
641
|
+
function houdini(x, ls, ms, opts) {
|
|
545
642
|
let set = ls.flatMap(l => { try {
|
|
546
|
-
const b = buildLaw(x, l,
|
|
643
|
+
const b = buildLaw(x, l, opts);
|
|
547
644
|
return b.kind === 'law' ? [{ l, law: b.law }] : [];
|
|
548
645
|
}
|
|
549
646
|
catch {
|
|
@@ -611,7 +708,7 @@ function prove(x0, l, ms, proven, ctx) {
|
|
|
611
708
|
if (isTwoRuns(l.expr))
|
|
612
709
|
two = buildTwoRuns(x, l, ctx?.others);
|
|
613
710
|
else
|
|
614
|
-
b = buildLaw(x, l,
|
|
711
|
+
b = buildLaw(x, l, ctx ?? {});
|
|
615
712
|
}
|
|
616
713
|
catch (e) {
|
|
617
714
|
return { ...base, verdict: 'not read', why: e.message, ms: 0 };
|
|
@@ -634,7 +731,7 @@ function prove(x0, l, ms, proven, ctx) {
|
|
|
634
731
|
}
|
|
635
732
|
// (from any state: a law about states proven with the others stated beside it, as one inductive set)
|
|
636
733
|
const beside = () => (ctx?.together ?? []).filter(m => m.name !== l.name).flatMap(m => { try {
|
|
637
|
-
const y = buildLaw(x, m,
|
|
734
|
+
const y = buildLaw(x, m, ctx ?? {});
|
|
638
735
|
return y.kind === 'law' ? [y.law] : [];
|
|
639
736
|
}
|
|
640
737
|
catch {
|
|
@@ -702,7 +799,7 @@ function proveInEnv(x, l, ms, proven, ctx) {
|
|
|
702
799
|
const bw = /^at\s+most\s+one\s+call\s+between\s+([\w.]+)\s+and\s+([\w.]+)$/i.exec(l.expr.trim());
|
|
703
800
|
let b;
|
|
704
801
|
try {
|
|
705
|
-
b = bw ? { kind: 'law', law: sys.between(l.name, bw[1], bw[2]) } : buildLaw(x, l,
|
|
802
|
+
b = bw ? { kind: 'law', law: sys.between(l.name, bw[1], bw[2]) } : buildLaw(x, l, ctx);
|
|
706
803
|
}
|
|
707
804
|
catch (e) {
|
|
708
805
|
return { ...base, verdict: 'not read', why: e.message, ms: 0 };
|
|
@@ -830,6 +927,10 @@ function shownValue(x, rule, vars, none) {
|
|
|
830
927
|
// A run as calls of the code: the constructor's arguments, then each request (the method, its arguments by the code's
|
|
831
928
|
// names, the answers and the clock), the last the one that breaks the law.
|
|
832
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
|
+
}
|
|
833
934
|
const names = namesWithClock(x), code = (n) => n.code;
|
|
834
935
|
const ps = names.filter(n => n.role === 'param' && n.rule && n.rule in run.params);
|
|
835
936
|
const lines = ps.length ? [`made with ${ps.map(n => `${code(n)} = ${shownValue(x, n.rule, run.params, n.none)}`).join(', ')}`] : [];
|
|
@@ -921,7 +1022,7 @@ export const proposedLaws = (x, lang, ms = 2000) => propose(x, lang, { ms, propo
|
|
|
921
1022
|
// --- printing ------------------------------------------------------------------------------------------------------------
|
|
922
1023
|
const ROLE = { state: 'state', param: 'made with', input: 'request', answer: 'answered', result: 'result', failed: 'failed', method: 'method', clock: 'clock', const: 'constant' };
|
|
923
1024
|
function printRule(r, o) {
|
|
924
|
-
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})`);
|
|
925
1026
|
if (!r.ok) {
|
|
926
1027
|
for (const f of r.refusals)
|
|
927
1028
|
out(` ${paint('yellow', `refused at ${f.where}:`)} ${f.what}`);
|
|
@@ -969,6 +1070,12 @@ function printRule(r, o) {
|
|
|
969
1070
|
for (const l of r.laws)
|
|
970
1071
|
law(l, false);
|
|
971
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
|
+
}
|
|
972
1079
|
if (r.proposed.length || r.brokenProposed) {
|
|
973
1080
|
out(' laws proposed (nothing written; state one with the comment under it):');
|
|
974
1081
|
for (const l of r.proposed)
|
|
@@ -982,15 +1089,20 @@ function printRule(r, o) {
|
|
|
982
1089
|
out();
|
|
983
1090
|
}
|
|
984
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);
|
|
985
|
-
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] [--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]
|
|
1093
|
+
gdp-wired draft <file> --clause <text> | --clause-file <file> --cite <ref> [--llm <command> | --answer <file>] [--by <who>]
|
|
986
1094
|
|
|
987
1095
|
Reads the rule in each file (Python, Ruby, Elixir, Java, Kotlin, Go, Rust, Swift, C, C++, TypeScript, Effect, XState), checks it
|
|
988
1096
|
against the code by running both, proves the laws stated in the code (\`# gdp: law <name>: <expr>\`, \`// gdp: law ...\`,
|
|
989
1097
|
@GdpLaw("<name>: <expr>")) and proposes others. Laws about two runs: \`<secret> never reaches <fields>\`, \`isolated by <argument>\`,
|
|
990
|
-
\`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);
|
|
991
1100
|
--cert <dir> writes each proven law's certificate (its meta the citations); --from any (or from = "any" in gdp.toml, for every
|
|
992
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
|
|
993
|
-
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.`;
|
|
994
1106
|
// Every target's rules and their laws, and the exit code (1: a stated law broken; 2: one not checked).
|
|
995
1107
|
export async function check(targets, given = {}, each) {
|
|
996
1108
|
const o = { ms: 10_000, propose: true, ...given }, all = [];
|
|
@@ -1002,22 +1114,76 @@ export async function check(targets, given = {}, each) {
|
|
|
1002
1114
|
rs.forEach(each);
|
|
1003
1115
|
}
|
|
1004
1116
|
const stated = all.flatMap(r => r.laws);
|
|
1005
|
-
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;
|
|
1006
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).
|
|
1007
1167
|
export async function main(argv) {
|
|
1008
1168
|
const { cmd, targets, o } = args(argv);
|
|
1169
|
+
if (cmd === 'draft' && targets.length === 1)
|
|
1170
|
+
return draft(targets[0], o);
|
|
1009
1171
|
if (cmd !== 'check' || !targets.length) {
|
|
1010
1172
|
out(USAGE);
|
|
1011
1173
|
return cmd === 'help' || cmd === '--help' || cmd === '-h' || !cmd ? 0 : 2;
|
|
1012
1174
|
}
|
|
1013
1175
|
tint = colors(proc.env, !!proc.stdout.isTTY, !!o.json);
|
|
1014
|
-
const { rules: all, exit:
|
|
1176
|
+
const { rules: all, exit: code0 } = await check(targets, o, o.json ? undefined : r => printRule(r, o));
|
|
1015
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;
|
|
1016
1180
|
if (o.json)
|
|
1017
1181
|
out(JSON.stringify({ rules: all.map(({ source: _s, ...r }) => r), exit: code }, null, 1));
|
|
1018
1182
|
else if (stated.length) {
|
|
1019
1183
|
const n = (v) => stated.filter(l => l.verdict === v).length;
|
|
1020
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('; ')}`);
|
|
1021
1187
|
}
|
|
1022
1188
|
return code;
|
|
1023
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> = {
|