@under18dev/veritas-property-engine 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +12 -2
- package/dist/approvals.d.ts +16 -0
- package/dist/approvals.d.ts.map +1 -0
- package/dist/approvals.js +86 -0
- package/dist/approvals.js.map +1 -0
- package/dist/diff.d.ts +17 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +24 -0
- package/dist/diff.js.map +1 -0
- package/dist/formalize.d.ts +29 -0
- package/dist/formalize.d.ts.map +1 -0
- package/dist/formalize.js +111 -0
- package/dist/formalize.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/inputs.d.ts +123 -0
- package/dist/inputs.d.ts.map +1 -0
- package/dist/inputs.js +31 -0
- package/dist/inputs.js.map +1 -0
- package/dist/predicates.d.ts +15 -0
- package/dist/predicates.d.ts.map +1 -0
- package/dist/predicates.js +40 -0
- package/dist/predicates.js.map +1 -0
- package/dist/registry.d.ts +44 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +378 -0
- package/dist/registry.js.map +1 -0
- package/package.json +27 -3
package/dist/inputs.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Structural copy of the discovery output this engine consumes (kept local to avoid coupling to its internals). */
|
|
3
|
+
export declare const ThresholdRelation: z.ZodObject<{
|
|
4
|
+
kind: z.ZodLiteral<"threshold">;
|
|
5
|
+
quantity: z.ZodString;
|
|
6
|
+
operator: z.ZodEnum<{
|
|
7
|
+
"<": "<";
|
|
8
|
+
"<=": "<=";
|
|
9
|
+
">": ">";
|
|
10
|
+
">=": ">=";
|
|
11
|
+
"==": "==";
|
|
12
|
+
}>;
|
|
13
|
+
value: z.ZodString;
|
|
14
|
+
consequence: z.ZodString;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export type ThresholdRelation = z.infer<typeof ThresholdRelation>;
|
|
17
|
+
export declare const StatementInput: z.ZodObject<{
|
|
18
|
+
id: z.ZodString;
|
|
19
|
+
sourceId: z.ZodString;
|
|
20
|
+
range: z.ZodObject<{
|
|
21
|
+
start: z.ZodNumber;
|
|
22
|
+
end: z.ZodNumber;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
quote: z.ZodString;
|
|
25
|
+
modality: z.ZodEnum<{
|
|
26
|
+
must: "must";
|
|
27
|
+
should: "should";
|
|
28
|
+
may: "may";
|
|
29
|
+
descriptive: "descriptive";
|
|
30
|
+
}>;
|
|
31
|
+
subjects: z.ZodArray<z.ZodString>;
|
|
32
|
+
relation: z.ZodUnion<readonly [z.ZodObject<{
|
|
33
|
+
kind: z.ZodLiteral<"threshold">;
|
|
34
|
+
quantity: z.ZodString;
|
|
35
|
+
operator: z.ZodEnum<{
|
|
36
|
+
"<": "<";
|
|
37
|
+
"<=": "<=";
|
|
38
|
+
">": ">";
|
|
39
|
+
">=": ">=";
|
|
40
|
+
"==": "==";
|
|
41
|
+
}>;
|
|
42
|
+
value: z.ZodString;
|
|
43
|
+
consequence: z.ZodString;
|
|
44
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
45
|
+
kind: z.ZodLiteral<"free_text">;
|
|
46
|
+
}, z.core.$strip>]>;
|
|
47
|
+
flags: z.ZodArray<z.ZodString>;
|
|
48
|
+
version: z.ZodOptional<z.ZodString>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
export type StatementInput = z.infer<typeof StatementInput>;
|
|
51
|
+
export declare const DiscoveryInput: z.ZodObject<{
|
|
52
|
+
sources: z.ZodArray<z.ZodObject<{
|
|
53
|
+
id: z.ZodString;
|
|
54
|
+
kind: z.ZodEnum<{
|
|
55
|
+
git: "git";
|
|
56
|
+
code: "code";
|
|
57
|
+
web: "web";
|
|
58
|
+
human: "human";
|
|
59
|
+
standard: "standard";
|
|
60
|
+
readme: "readme";
|
|
61
|
+
docs: "docs";
|
|
62
|
+
test: "test";
|
|
63
|
+
issue: "issue";
|
|
64
|
+
pr: "pr";
|
|
65
|
+
runtime: "runtime";
|
|
66
|
+
}>;
|
|
67
|
+
locator: z.ZodString;
|
|
68
|
+
revision: z.ZodOptional<z.ZodString>;
|
|
69
|
+
range: z.ZodOptional<z.ZodObject<{
|
|
70
|
+
start: z.ZodNumber;
|
|
71
|
+
end: z.ZodNumber;
|
|
72
|
+
}, z.core.$strip>>;
|
|
73
|
+
capturedAt: z.ZodISODateTime;
|
|
74
|
+
contentHash: z.ZodString;
|
|
75
|
+
derivedFrom: z.ZodArray<z.ZodString>;
|
|
76
|
+
summary: z.ZodString;
|
|
77
|
+
trust: z.ZodLiteral<"untrusted_data">;
|
|
78
|
+
}, z.core.$strip>>;
|
|
79
|
+
statements: z.ZodArray<z.ZodObject<{
|
|
80
|
+
id: z.ZodString;
|
|
81
|
+
sourceId: z.ZodString;
|
|
82
|
+
range: z.ZodObject<{
|
|
83
|
+
start: z.ZodNumber;
|
|
84
|
+
end: z.ZodNumber;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
quote: z.ZodString;
|
|
87
|
+
modality: z.ZodEnum<{
|
|
88
|
+
must: "must";
|
|
89
|
+
should: "should";
|
|
90
|
+
may: "may";
|
|
91
|
+
descriptive: "descriptive";
|
|
92
|
+
}>;
|
|
93
|
+
subjects: z.ZodArray<z.ZodString>;
|
|
94
|
+
relation: z.ZodUnion<readonly [z.ZodObject<{
|
|
95
|
+
kind: z.ZodLiteral<"threshold">;
|
|
96
|
+
quantity: z.ZodString;
|
|
97
|
+
operator: z.ZodEnum<{
|
|
98
|
+
"<": "<";
|
|
99
|
+
"<=": "<=";
|
|
100
|
+
">": ">";
|
|
101
|
+
">=": ">=";
|
|
102
|
+
"==": "==";
|
|
103
|
+
}>;
|
|
104
|
+
value: z.ZodString;
|
|
105
|
+
consequence: z.ZodString;
|
|
106
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
107
|
+
kind: z.ZodLiteral<"free_text">;
|
|
108
|
+
}, z.core.$strip>]>;
|
|
109
|
+
flags: z.ZodArray<z.ZodString>;
|
|
110
|
+
version: z.ZodOptional<z.ZodString>;
|
|
111
|
+
}, z.core.$strip>>;
|
|
112
|
+
provenance: z.ZodArray<z.ZodObject<{
|
|
113
|
+
from: z.ZodString;
|
|
114
|
+
to: z.ZodString;
|
|
115
|
+
relation: z.ZodEnum<{
|
|
116
|
+
duplicate_of: "duplicate_of";
|
|
117
|
+
derived_from: "derived_from";
|
|
118
|
+
supersedes: "supersedes";
|
|
119
|
+
}>;
|
|
120
|
+
}, z.core.$strip>>;
|
|
121
|
+
}, z.core.$strip>;
|
|
122
|
+
export type DiscoveryInput = z.infer<typeof DiscoveryInput>;
|
|
123
|
+
//# sourceMappingURL=inputs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../src/inputs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,oHAAoH;AACpH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;iBAM5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAUzB,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE5D,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAUzB,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
package/dist/inputs.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EvidenceSource } from '@under18dev/veritas-core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/** Structural copy of the discovery output this engine consumes (kept local to avoid coupling to its internals). */
|
|
4
|
+
export const ThresholdRelation = z.object({
|
|
5
|
+
kind: z.literal('threshold'),
|
|
6
|
+
quantity: z.string(),
|
|
7
|
+
operator: z.enum(['<', '<=', '>', '>=', '==']),
|
|
8
|
+
value: z.string().regex(/^-?\d+$/),
|
|
9
|
+
consequence: z.string(),
|
|
10
|
+
});
|
|
11
|
+
export const StatementInput = z.object({
|
|
12
|
+
id: z.string(),
|
|
13
|
+
sourceId: z.string(),
|
|
14
|
+
range: z.object({ start: z.number().int(), end: z.number().int() }),
|
|
15
|
+
quote: z.string(),
|
|
16
|
+
modality: z.enum(['must', 'should', 'may', 'descriptive']),
|
|
17
|
+
subjects: z.array(z.string()),
|
|
18
|
+
relation: z.union([ThresholdRelation, z.object({ kind: z.literal('free_text') })]),
|
|
19
|
+
flags: z.array(z.string()),
|
|
20
|
+
version: z.string().optional(),
|
|
21
|
+
});
|
|
22
|
+
export const DiscoveryInput = z.object({
|
|
23
|
+
sources: z.array(EvidenceSource),
|
|
24
|
+
statements: z.array(StatementInput),
|
|
25
|
+
provenance: z.array(z.object({
|
|
26
|
+
from: z.string(),
|
|
27
|
+
to: z.string(),
|
|
28
|
+
relation: z.enum(['duplicate_of', 'derived_from', 'supersedes']),
|
|
29
|
+
})),
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=inputs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputs.js","sourceRoot":"","sources":["../src/inputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,oHAAoH;AACpH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC;IAClC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;CACxB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC;IACnE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;IAC1D,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC7B,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;IAClF,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC;IAChC,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC;IACnC,UAAU,EAAE,CAAC,CAAC,KAAK,CACjB,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;QACd,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;KACjE,CAAC,CACH;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Op = '<' | '<=' | '>' | '>=' | '==';
|
|
2
|
+
/** An integer predicate on one variable as a closed interval [lo, hi] (null = unbounded), or a point. */
|
|
3
|
+
export interface Interval {
|
|
4
|
+
lo: bigint | null;
|
|
5
|
+
hi: bigint | null;
|
|
6
|
+
}
|
|
7
|
+
/** Normalize `x op v` over the integers, e.g. `x > 1000` becomes [1001, +inf). */
|
|
8
|
+
export declare function toInterval(op: Op, value: string): Interval;
|
|
9
|
+
export declare function sameInterval(a: Interval, b: Interval): boolean;
|
|
10
|
+
/** The complement of a one-sided interval, so `if (x < 1000) return 0` agrees with `x >= 1000`. */
|
|
11
|
+
export declare function complement(i: Interval): Interval | null;
|
|
12
|
+
/** Code comparison operators normalized to the parameter's side (`1000 < x` is `x > 1000`). */
|
|
13
|
+
export declare function normalizeComparison(op: string, paramOnLeft: boolean): Op | null;
|
|
14
|
+
export declare function describe(param: string, op: Op, value: string): string;
|
|
15
|
+
//# sourceMappingURL=predicates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,EAAE,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAEhD,yGAAyG;AACzG,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CACnB;AAED,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAe1D;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,OAAO,CAE9D;AAED,mGAAmG;AACnG,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAMvD;AAID,+FAA+F;AAC/F,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,EAAE,GAAG,IAAI,CAO/E;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAErE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Normalize `x op v` over the integers, e.g. `x > 1000` becomes [1001, +inf). */
|
|
2
|
+
export function toInterval(op, value) {
|
|
3
|
+
const v = BigInt(value);
|
|
4
|
+
switch (op) {
|
|
5
|
+
case '>':
|
|
6
|
+
return { lo: v + 1n, hi: null };
|
|
7
|
+
case '>=':
|
|
8
|
+
return { lo: v, hi: null };
|
|
9
|
+
case '<':
|
|
10
|
+
return { lo: null, hi: v - 1n };
|
|
11
|
+
case '<=':
|
|
12
|
+
return { lo: null, hi: v };
|
|
13
|
+
case '==':
|
|
14
|
+
return { lo: v, hi: v };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function sameInterval(a, b) {
|
|
18
|
+
return a.lo === b.lo && a.hi === b.hi;
|
|
19
|
+
}
|
|
20
|
+
/** The complement of a one-sided interval, so `if (x < 1000) return 0` agrees with `x >= 1000`. */
|
|
21
|
+
export function complement(i) {
|
|
22
|
+
if (i.lo !== null && i.hi === null)
|
|
23
|
+
return { lo: null, hi: i.lo - 1n };
|
|
24
|
+
if (i.lo === null && i.hi !== null)
|
|
25
|
+
return { lo: i.hi + 1n, hi: null };
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const FLIP = { '<': '>', '<=': '>=', '>': '<', '>=': '<=', '==': '==', '===': '==' };
|
|
29
|
+
/** Code comparison operators normalized to the parameter's side (`1000 < x` is `x > 1000`). */
|
|
30
|
+
export function normalizeComparison(op, paramOnLeft) {
|
|
31
|
+
const base = { '<': '<', '<=': '<=', '>': '>', '>=': '>=', '===': '==', '==': '==' };
|
|
32
|
+
const o = base[op];
|
|
33
|
+
if (!o)
|
|
34
|
+
return null;
|
|
35
|
+
return paramOnLeft ? o : FLIP[o];
|
|
36
|
+
}
|
|
37
|
+
export function describe(param, op, value) {
|
|
38
|
+
return `${param} ${op} ${value}`;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=predicates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicates.js","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AAQA,kFAAkF;AAClF,MAAM,UAAU,UAAU,CAAC,EAAM,EAAE,KAAa;IAC9C,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAExB,QAAQ,EAAE,EAAE,CAAC;QACX,KAAK,GAAG;YACN,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;QAClC,KAAK,IAAI;YACP,OAAO,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;QAC7B,KAAK,GAAG;YACN,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC;QAClC,KAAK,IAAI;YACP,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;QAC7B,KAAK,IAAI;YACP,OAAO,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,CAAW,EAAE,CAAW;IACnD,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;AACxC,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,UAAU,CAAC,CAAW;IACpC,IAAI,CAAC,CAAC,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC,EAAE,KAAK,IAAI;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;IAEvE,IAAI,CAAC,CAAC,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC,EAAE,KAAK,IAAI;QAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IAEvE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,IAAI,GAAuB,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAEzG,+FAA+F;AAC/F,MAAM,UAAU,mBAAmB,CAAC,EAAU,EAAE,WAAoB;IAClE,MAAM,IAAI,GAAuB,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACzG,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IAEnB,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAEpB,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,IAAI,CAAC,CAAC,CAAQ,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,EAAM,EAAE,KAAa;IAC3D,OAAO,GAAG,KAAK,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { BehaviorCandidate, CodeIndex, FunctionInfo } from '@under18dev/veritas-code-intelligence';
|
|
2
|
+
import { type Property } from '@under18dev/veritas-core';
|
|
3
|
+
import type { DiscoveryInput } from './inputs.js';
|
|
4
|
+
import { type Op } from './predicates.js';
|
|
5
|
+
export interface ConflictGroup {
|
|
6
|
+
id: string;
|
|
7
|
+
symbol: string;
|
|
8
|
+
param: string;
|
|
9
|
+
propertyIds: string[];
|
|
10
|
+
/** Suggested reading for the human decision; never applied automatically. */
|
|
11
|
+
preferredPropertyId: string | null;
|
|
12
|
+
rationale: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface MappingNote {
|
|
15
|
+
statementId: string;
|
|
16
|
+
status: 'mapped' | 'unmapped' | 'not_threshold' | 'stale' | 'duplicate';
|
|
17
|
+
symbol: string | null;
|
|
18
|
+
reason: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Registry {
|
|
21
|
+
properties: Property[];
|
|
22
|
+
conflicts: ConflictGroup[];
|
|
23
|
+
mapping: MappingNote[];
|
|
24
|
+
}
|
|
25
|
+
/** Compare the documented predicate with the implementation's comparisons on the same parameter. */
|
|
26
|
+
export declare function implementationAgreement(fn: FunctionInfo, param: string, op: Op, value: string): Property['implementationAgreement'];
|
|
27
|
+
/** Compare dotted numeric versions (`2.10.0` > `2.9`); missing parts count as 0. */
|
|
28
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
29
|
+
export interface BuildOptions {
|
|
30
|
+
discovery: DiscoveryInput;
|
|
31
|
+
code: CodeIndex;
|
|
32
|
+
candidates: BehaviorCandidate[];
|
|
33
|
+
/** Previous registry, used to bump versions when a property's content changes. */
|
|
34
|
+
previous?: Property[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Build the property registry. Normative statements become `proposed` properties; inferred candidates become
|
|
38
|
+
* experimental `proposed` properties; conflicting claims become `conflicted`. Nothing is ever `accepted` here:
|
|
39
|
+
* only approval records (see approvals.ts) change review status.
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildRegistry(options: BuildOptions): Registry;
|
|
42
|
+
/** Hash of the fields an approval is about; review state and confidence are excluded. */
|
|
43
|
+
export declare function contentHash(p: Property): string;
|
|
44
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AACxG,OAAO,EAGL,KAAK,QAAQ,EAGd,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAqC,MAAM,aAAa,CAAC;AACrF,OAAO,EAAmC,KAAK,EAAE,EAA4B,MAAM,iBAAiB,CAAC;AAErG,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,6EAA6E;IAC7E,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,eAAe,GAAG,OAAO,GAAG,WAAW,CAAC;IACxE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,QAAQ,EAAE,CAAC;IACvB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB;AAiHD,oGAAoG;AACpG,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,YAAY,EAChB,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,MAAM,GACZ,QAAQ,CAAC,yBAAyB,CAAC,CAoBrC;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAW5D;AA4BD,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,cAAc,CAAC;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,kFAAkF;IAClF,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,QAAQ,CAgQ7D;AAED,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAQ/C"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { hashValue, stableId, } from '@under18dev/veritas-core';
|
|
2
|
+
import { complement, normalizeComparison, sameInterval, toInterval } from './predicates.js';
|
|
3
|
+
/** Crude singular form, so "passes", "orders" and "boxes" match "pass", "order" and "box". */
|
|
4
|
+
function singular(w) {
|
|
5
|
+
if (w.length > 4 && /(?:ss|sh|ch|x|z)es$/.test(w))
|
|
6
|
+
return w.slice(0, -2);
|
|
7
|
+
if (w.length > 3 && w.endsWith('s') && !w.endsWith('ss'))
|
|
8
|
+
return w.slice(0, -1);
|
|
9
|
+
return w;
|
|
10
|
+
}
|
|
11
|
+
const words = (text) => text
|
|
12
|
+
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
13
|
+
.toLowerCase()
|
|
14
|
+
.split(/[^a-z0-9]+/)
|
|
15
|
+
.filter((w) => w.length > 2)
|
|
16
|
+
.map(singular);
|
|
17
|
+
const QUALITY = {
|
|
18
|
+
readme: 'primary',
|
|
19
|
+
docs: 'primary',
|
|
20
|
+
standard: 'primary',
|
|
21
|
+
human: 'primary',
|
|
22
|
+
issue: 'secondary',
|
|
23
|
+
pr: 'secondary',
|
|
24
|
+
web: 'secondary',
|
|
25
|
+
git: 'derived',
|
|
26
|
+
code: 'implementation',
|
|
27
|
+
test: 'implementation',
|
|
28
|
+
runtime: 'implementation',
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Whether a statement is about how many elements an array has: it says count/number of/length/size, or puts
|
|
32
|
+
* the number right before the array's noun ("3 or more items", "at least 2 values") without an ordinal
|
|
33
|
+
* ("the second value" is about one element).
|
|
34
|
+
*/
|
|
35
|
+
function lengthStatement(quote, arrayWords) {
|
|
36
|
+
if (/\b(?:first|second|third|fourth|fifth|last|\d+(?:st|nd|rd|th))\s+\w+/i.test(quote))
|
|
37
|
+
return false;
|
|
38
|
+
if (/\b(?:count|number of|length|size|how many)\b/i.test(quote))
|
|
39
|
+
return true;
|
|
40
|
+
// "3 or more items", "at least 3 items", "up to 5 values": a number right before the array's noun.
|
|
41
|
+
return arrayWords.some((noun) => new RegExp(`\\d[\\d,]*\\s+(?:or\\s+(?:more|fewer|less)\\s+)?${noun}`, 'i').test(quote));
|
|
42
|
+
}
|
|
43
|
+
/** Pick the function and parameter a threshold statement talks about, or null when nothing fits clearly. */
|
|
44
|
+
function mapStatement(statement, relation, index) {
|
|
45
|
+
const quoteWords = new Set([...words(statement.quote), ...statement.subjects.flatMap(words)]);
|
|
46
|
+
const quantityWords = words(relation.quantity);
|
|
47
|
+
const scored = [];
|
|
48
|
+
for (const fn of index.functions) {
|
|
49
|
+
if (!fn.exported)
|
|
50
|
+
continue;
|
|
51
|
+
// Number parameters, and fields of record parameters the function compares (`order.total`).
|
|
52
|
+
const numeric = [
|
|
53
|
+
...fn.params
|
|
54
|
+
.filter((p) => /\bnumber\b/.test(p.type) && !/\[\]|Array</.test(p.type))
|
|
55
|
+
.map((p) => ({ name: p.name, words: words(p.name) })),
|
|
56
|
+
...[
|
|
57
|
+
...new Set(fn.comparisons.map((c) => c.param).filter((n) => n?.includes('.') ?? false)),
|
|
58
|
+
].map((name) => ({ name, words: words(name.slice(name.indexOf('.') + 1)) })),
|
|
59
|
+
];
|
|
60
|
+
if (numeric.length === 0)
|
|
61
|
+
continue;
|
|
62
|
+
const nameHits = words(fn.name).filter((w) => quoteWords.has(w)).length;
|
|
63
|
+
for (const p of numeric) {
|
|
64
|
+
// An array's length only when the statement talks about a count ("3 or more items", "the item count"),
|
|
65
|
+
// never about one element ("the second value") and never on the function name alone.
|
|
66
|
+
if (p.name.endsWith('.length')) {
|
|
67
|
+
const arrayWords = words(p.name.slice(0, -'.length'.length));
|
|
68
|
+
if (!lengthStatement(statement.quote, arrayWords))
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const paramWords = p.words;
|
|
72
|
+
const paramHit = p.name.endsWith('.length') ||
|
|
73
|
+
quantityWords.some((w) => paramWords.includes(w)) ||
|
|
74
|
+
paramWords.some((w) => quoteWords.has(w));
|
|
75
|
+
const compared = fn.comparisons.some((c) => c.param === p.name);
|
|
76
|
+
const score = (paramHit ? 2 : 0) +
|
|
77
|
+
nameHits * 2 +
|
|
78
|
+
(compared ? 1 : 0) +
|
|
79
|
+
(numeric.length === 1 && nameHits > 0 ? 1 : 0);
|
|
80
|
+
if (paramHit || nameHits > 0)
|
|
81
|
+
scored.push({ fn, param: p.name, score });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
scored.sort((a, b) => b.score - a.score);
|
|
85
|
+
const [best, second] = scored;
|
|
86
|
+
if (!best || best.score < 3)
|
|
87
|
+
return null;
|
|
88
|
+
if (second && second.score === best.score)
|
|
89
|
+
return null;
|
|
90
|
+
return best;
|
|
91
|
+
}
|
|
92
|
+
/** Compare the documented predicate with the implementation's comparisons on the same parameter. */
|
|
93
|
+
export function implementationAgreement(fn, param, op, value) {
|
|
94
|
+
const documented = toInterval(op, value);
|
|
95
|
+
let near = false;
|
|
96
|
+
for (const c of fn.comparisons) {
|
|
97
|
+
if (c.param !== param || c.literal === null)
|
|
98
|
+
continue;
|
|
99
|
+
const paramOnLeft = c.left.trim() === param;
|
|
100
|
+
const codeOp = normalizeComparison(c.operator, paramOnLeft);
|
|
101
|
+
if (!codeOp)
|
|
102
|
+
continue;
|
|
103
|
+
const code = toInterval(codeOp, c.literal);
|
|
104
|
+
const negated = complement(code);
|
|
105
|
+
if (sameInterval(code, documented) || (negated && sameInterval(negated, documented)))
|
|
106
|
+
return 'agree';
|
|
107
|
+
const distance = BigInt(c.literal) - BigInt(value);
|
|
108
|
+
if (distance >= -1n && distance <= 1n)
|
|
109
|
+
near = true;
|
|
110
|
+
}
|
|
111
|
+
return near ? 'disagree' : 'unknown';
|
|
112
|
+
}
|
|
113
|
+
/** Compare dotted numeric versions (`2.10.0` > `2.9`); missing parts count as 0. */
|
|
114
|
+
export function compareVersions(a, b) {
|
|
115
|
+
const pa = a.split('.').map(Number);
|
|
116
|
+
const pb = b.split('.').map(Number);
|
|
117
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
118
|
+
const d = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
119
|
+
if (d !== 0)
|
|
120
|
+
return d;
|
|
121
|
+
}
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
function sourceRank(source, statement) {
|
|
125
|
+
if (!source)
|
|
126
|
+
return 0;
|
|
127
|
+
let rank = {
|
|
128
|
+
human: 6,
|
|
129
|
+
standard: 5,
|
|
130
|
+
readme: 4,
|
|
131
|
+
docs: 4,
|
|
132
|
+
issue: 3,
|
|
133
|
+
pr: 3,
|
|
134
|
+
web: 2,
|
|
135
|
+
git: 1,
|
|
136
|
+
code: 0,
|
|
137
|
+
test: 0,
|
|
138
|
+
runtime: 0,
|
|
139
|
+
}[source.kind];
|
|
140
|
+
if (/\b(decision|decided|supersede|outdated|replaces)\b/i.test(statement.quote) ||
|
|
141
|
+
/\b(decision|outdated)\b/i.test(source.summary)) {
|
|
142
|
+
rank += 3;
|
|
143
|
+
}
|
|
144
|
+
return rank;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Build the property registry. Normative statements become `proposed` properties; inferred candidates become
|
|
148
|
+
* experimental `proposed` properties; conflicting claims become `conflicted`. Nothing is ever `accepted` here:
|
|
149
|
+
* only approval records (see approvals.ts) change review status.
|
|
150
|
+
*/
|
|
151
|
+
export function buildRegistry(options) {
|
|
152
|
+
const { discovery, code } = options;
|
|
153
|
+
const sources = new Map(discovery.sources.map((s) => [s.id, s]));
|
|
154
|
+
const duplicateOf = new Map(discovery.provenance.filter((p) => p.relation === 'duplicate_of').map((p) => [p.from, p.to]));
|
|
155
|
+
// Sources that copy statements of another source are not independent evidence for them.
|
|
156
|
+
const derived = new Set(discovery.provenance.filter((p) => p.relation === 'derived_from').map((p) => p.from));
|
|
157
|
+
// Sources another source calls outdated. That claim is itself untrusted data: it lowers the source's
|
|
158
|
+
// freshness and its rank as a suggestion, but never removes it from a conflict.
|
|
159
|
+
const supersededBy = new Map();
|
|
160
|
+
for (const p of discovery.provenance.filter((e) => e.relation === 'supersedes'))
|
|
161
|
+
supersededBy.set(p.to, [...(supersededBy.get(p.to) ?? []), p.from]);
|
|
162
|
+
const mapping = [];
|
|
163
|
+
const bySymbolParam = new Map();
|
|
164
|
+
const properties = [];
|
|
165
|
+
for (const statement of discovery.statements) {
|
|
166
|
+
const source = sources.get(statement.sourceId);
|
|
167
|
+
if (statement.relation.kind !== 'threshold') {
|
|
168
|
+
mapping.push({
|
|
169
|
+
statementId: statement.id,
|
|
170
|
+
status: 'not_threshold',
|
|
171
|
+
symbol: null,
|
|
172
|
+
reason: 'free-text statement; kept as evidence only',
|
|
173
|
+
});
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const canonical = duplicateOf.get(statement.sourceId) ?? duplicateOf.get(statement.id);
|
|
177
|
+
if (canonical) {
|
|
178
|
+
mapping.push({
|
|
179
|
+
statementId: statement.id,
|
|
180
|
+
status: 'duplicate',
|
|
181
|
+
symbol: null,
|
|
182
|
+
reason: `duplicate of ${canonical}; not counted as independent`,
|
|
183
|
+
});
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const relation = statement.relation;
|
|
187
|
+
const target = mapStatement(statement, relation, code);
|
|
188
|
+
if (!target) {
|
|
189
|
+
mapping.push({
|
|
190
|
+
statementId: statement.id,
|
|
191
|
+
status: 'unmapped',
|
|
192
|
+
symbol: null,
|
|
193
|
+
reason: 'no single exported function and parameter clearly matches',
|
|
194
|
+
});
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const stale = statement.flags.includes('stale');
|
|
198
|
+
const instructionLike = statement.flags.includes('instruction_like');
|
|
199
|
+
const llmExtracted = statement.flags.includes('llm_extracted');
|
|
200
|
+
const agreement = implementationAgreement(target.fn, target.param, relation.operator, relation.value);
|
|
201
|
+
const citation = `${source?.locator ?? statement.sourceId}:${statement.range.start}`;
|
|
202
|
+
const property = {
|
|
203
|
+
id: stableId('P', {
|
|
204
|
+
symbol: target.fn.symbol,
|
|
205
|
+
param: target.param,
|
|
206
|
+
op: relation.operator,
|
|
207
|
+
value: relation.value,
|
|
208
|
+
statement: statement.id,
|
|
209
|
+
}),
|
|
210
|
+
version: 1,
|
|
211
|
+
description: `${target.fn.name}: ${target.param} ${relation.operator} ${relation.value} -> ${relation.consequence}`.slice(0, 500),
|
|
212
|
+
template: 'boundary',
|
|
213
|
+
targetSymbols: [target.fn.symbol],
|
|
214
|
+
status: 'proposed',
|
|
215
|
+
origin: 'normative',
|
|
216
|
+
sourceIds: [statement.sourceId],
|
|
217
|
+
assumptions: [`the statement at ${citation} refers to ${target.fn.symbol} parameter ${target.param}`],
|
|
218
|
+
inputDomain: { [target.param]: 'integer' },
|
|
219
|
+
formalExpression: `${target.param} ${relation.operator} ${relation.value}`,
|
|
220
|
+
predicate: {
|
|
221
|
+
param: target.param,
|
|
222
|
+
operator: relation.operator,
|
|
223
|
+
value: relation.value,
|
|
224
|
+
consequence: relation.consequence,
|
|
225
|
+
},
|
|
226
|
+
statementIds: [statement.id],
|
|
227
|
+
citations: [citation],
|
|
228
|
+
conflictsWith: [],
|
|
229
|
+
confidence: {
|
|
230
|
+
sourceQuality: source ? QUALITY[source.kind] : 'unknown',
|
|
231
|
+
agreement: 'single_source',
|
|
232
|
+
implementationAlignment: agreement,
|
|
233
|
+
independence: source && QUALITY[source.kind] === 'implementation'
|
|
234
|
+
? 'circular'
|
|
235
|
+
: derived.has(statement.sourceId)
|
|
236
|
+
? 'derived'
|
|
237
|
+
: 'independent',
|
|
238
|
+
freshness: stale || supersededBy.has(statement.sourceId) ? 'stale' : 'current',
|
|
239
|
+
},
|
|
240
|
+
implementationAgreement: agreement,
|
|
241
|
+
experimental: instructionLike || llmExtracted,
|
|
242
|
+
};
|
|
243
|
+
if (instructionLike)
|
|
244
|
+
property.assumptions.push('source text contains instruction-like content; treated as data only');
|
|
245
|
+
if (llmExtracted)
|
|
246
|
+
property.assumptions.push('threshold read by an LLM from free text; not reproducible, review before accepting');
|
|
247
|
+
properties.push(property);
|
|
248
|
+
mapping.push({
|
|
249
|
+
statementId: statement.id,
|
|
250
|
+
status: stale ? 'stale' : 'mapped',
|
|
251
|
+
symbol: target.fn.symbol,
|
|
252
|
+
reason: `matched ${target.fn.name}(${target.param})`,
|
|
253
|
+
});
|
|
254
|
+
const key = `${target.fn.symbol}#${target.param}`;
|
|
255
|
+
const group = bySymbolParam.get(key) ?? [];
|
|
256
|
+
group.push({ property, statement, stale });
|
|
257
|
+
bySymbolParam.set(key, group);
|
|
258
|
+
}
|
|
259
|
+
const conflicts = [];
|
|
260
|
+
for (const [key, group] of bySymbolParam) {
|
|
261
|
+
const live = group.filter((g) => !g.stale);
|
|
262
|
+
// Merge claims that say the same thing (same interval) from different sources.
|
|
263
|
+
const distinct = new Map();
|
|
264
|
+
for (const g of live) {
|
|
265
|
+
const p = g.property.predicate;
|
|
266
|
+
const iv = toInterval(p.operator, p.value);
|
|
267
|
+
const k = `${iv.lo}:${iv.hi}`;
|
|
268
|
+
distinct.set(k, [...(distinct.get(k) ?? []), g]);
|
|
269
|
+
}
|
|
270
|
+
for (const same of distinct.values()) {
|
|
271
|
+
if (same.length > 1) {
|
|
272
|
+
// Agreement needs two sources that are not copies of each other.
|
|
273
|
+
const independent = new Set(same.filter((g) => !derived.has(g.statement.sourceId)).map((g) => g.statement.sourceId));
|
|
274
|
+
for (const g of same) {
|
|
275
|
+
if (independent.size >= 2)
|
|
276
|
+
g.property.confidence.agreement = 'agree';
|
|
277
|
+
g.property.sourceIds = [...new Set(same.flatMap((s) => s.property.sourceIds))];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (distinct.size > 1) {
|
|
282
|
+
const ids = live.map((g) => g.property.id);
|
|
283
|
+
for (const g of live) {
|
|
284
|
+
g.property.status = 'conflicted';
|
|
285
|
+
g.property.conflictsWith = ids.filter((id) => id !== g.property.id);
|
|
286
|
+
g.property.confidence.agreement = 'disagree';
|
|
287
|
+
}
|
|
288
|
+
// A statement from a newer release outranks one from an older release of the same project.
|
|
289
|
+
const versions = live.map((g) => g.statement.version).filter((v) => v !== undefined);
|
|
290
|
+
const newest = versions.length ? versions.reduce((a, b) => (compareVersions(a, b) >= 0 ? a : b)) : null;
|
|
291
|
+
const rankOf = (g) => {
|
|
292
|
+
const base = sourceRank(sources.get(g.statement.sourceId), g.statement) -
|
|
293
|
+
(supersededBy.has(g.statement.sourceId) ? 2 : 0);
|
|
294
|
+
const v = g.statement.version;
|
|
295
|
+
if (!v || !newest || versions.length < 2)
|
|
296
|
+
return base;
|
|
297
|
+
return base + (compareVersions(v, newest) === 0 ? 2 : -2);
|
|
298
|
+
};
|
|
299
|
+
const ranked = [...live].sort((a, b) => rankOf(b) - rankOf(a));
|
|
300
|
+
const [top, next] = ranked;
|
|
301
|
+
const tie = top && next && rankOf(top) === rankOf(next);
|
|
302
|
+
const [symbol, param] = [key.slice(0, key.lastIndexOf('#')), key.slice(key.lastIndexOf('#') + 1)];
|
|
303
|
+
conflicts.push({
|
|
304
|
+
id: stableId('CF', ids.sort()),
|
|
305
|
+
symbol,
|
|
306
|
+
param,
|
|
307
|
+
propertyIds: ids,
|
|
308
|
+
preferredPropertyId: tie || !top ? null : top.property.id,
|
|
309
|
+
rationale: [
|
|
310
|
+
...live.map((g) => `${g.property.citations[0]}: ${g.property.formalExpression} (${sources.get(g.statement.sourceId)?.kind ?? 'unknown'}${g.statement.version ? `, version ${g.statement.version}` : ''})`),
|
|
311
|
+
tie || !top
|
|
312
|
+
? 'no source is clearly preferable; a human decision is required'
|
|
313
|
+
: `suggested: ${top.property.citations[0]} (newer release, higher source rank or an explicit decision/outdated marker); not applied without approval`,
|
|
314
|
+
...group
|
|
315
|
+
.filter((g) => g.stale)
|
|
316
|
+
.map((g) => `${g.property.citations[0]} is marked stale and was not counted`),
|
|
317
|
+
...live
|
|
318
|
+
.filter((g) => supersededBy.has(g.statement.sourceId))
|
|
319
|
+
.map((g) => `${g.property.citations[0]} is called outdated by ${(supersededBy.get(g.statement.sourceId) ?? []).map((id) => sources.get(id)?.locator ?? id).join(', ')}; still counted until a human decides`),
|
|
320
|
+
],
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
for (const candidate of options.candidates) {
|
|
325
|
+
properties.push({
|
|
326
|
+
id: stableId('P', { candidate: candidate.id }),
|
|
327
|
+
version: 1,
|
|
328
|
+
description: candidate.description,
|
|
329
|
+
template: candidate.template,
|
|
330
|
+
targetSymbols: [candidate.symbol],
|
|
331
|
+
status: 'proposed',
|
|
332
|
+
origin: 'inferred',
|
|
333
|
+
sourceIds: [],
|
|
334
|
+
assumptions: [
|
|
335
|
+
'inferred from the implementation; not independent evidence of intended behaviour',
|
|
336
|
+
...candidate.notes,
|
|
337
|
+
],
|
|
338
|
+
inputDomain: {},
|
|
339
|
+
...(candidate.boundary
|
|
340
|
+
? {
|
|
341
|
+
formalExpression: `${candidate.boundary.param} ${candidate.boundary.operator} ${candidate.boundary.value}`,
|
|
342
|
+
}
|
|
343
|
+
: {}),
|
|
344
|
+
statementIds: [],
|
|
345
|
+
citations: [],
|
|
346
|
+
conflictsWith: [],
|
|
347
|
+
confidence: {
|
|
348
|
+
sourceQuality: 'implementation',
|
|
349
|
+
agreement: 'single_source',
|
|
350
|
+
implementationAlignment: 'agree',
|
|
351
|
+
independence: 'circular',
|
|
352
|
+
freshness: 'current',
|
|
353
|
+
},
|
|
354
|
+
implementationAgreement: 'unknown',
|
|
355
|
+
experimental: true,
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
const previous = new Map((options.previous ?? []).map((p) => [p.id, p]));
|
|
359
|
+
for (const p of properties) {
|
|
360
|
+
const before = previous.get(p.id);
|
|
361
|
+
if (before && contentHash(before) !== contentHash(p))
|
|
362
|
+
p.version = before.version + 1;
|
|
363
|
+
else if (before)
|
|
364
|
+
p.version = before.version;
|
|
365
|
+
}
|
|
366
|
+
return { properties, conflicts, mapping };
|
|
367
|
+
}
|
|
368
|
+
/** Hash of the fields an approval is about; review state and confidence are excluded. */
|
|
369
|
+
export function contentHash(p) {
|
|
370
|
+
return hashValue({
|
|
371
|
+
description: p.description,
|
|
372
|
+
predicate: p.predicate,
|
|
373
|
+
targetSymbols: p.targetSymbols,
|
|
374
|
+
sourceIds: p.sourceIds,
|
|
375
|
+
template: p.template,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
//# sourceMappingURL=registry.js.map
|