@mneme-ai/core 2.68.0 → 2.70.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/dist/grok_bridge/black_box.d.ts +29 -0
- package/dist/grok_bridge/black_box.d.ts.map +1 -0
- package/dist/grok_bridge/black_box.js +116 -0
- package/dist/grok_bridge/black_box.js.map +1 -0
- package/dist/grok_bridge/colossus_probe.d.ts +47 -0
- package/dist/grok_bridge/colossus_probe.d.ts.map +1 -0
- package/dist/grok_bridge/colossus_probe.js +83 -0
- package/dist/grok_bridge/colossus_probe.js.map +1 -0
- package/dist/grok_bridge/compliance_edition.d.ts +28 -0
- package/dist/grok_bridge/compliance_edition.d.ts.map +1 -0
- package/dist/grok_bridge/compliance_edition.js +100 -0
- package/dist/grok_bridge/compliance_edition.js.map +1 -0
- package/dist/grok_bridge/constitutional_double.d.ts +20 -0
- package/dist/grok_bridge/constitutional_double.d.ts.map +1 -0
- package/dist/grok_bridge/constitutional_double.js +87 -0
- package/dist/grok_bridge/constitutional_double.js.map +1 -0
- package/dist/grok_bridge/contra_rag.d.ts +27 -0
- package/dist/grok_bridge/contra_rag.d.ts.map +1 -0
- package/dist/grok_bridge/contra_rag.js +103 -0
- package/dist/grok_bridge/contra_rag.js.map +1 -0
- package/dist/grok_bridge/elon_chronostasis.d.ts +53 -0
- package/dist/grok_bridge/elon_chronostasis.d.ts.map +1 -0
- package/dist/grok_bridge/elon_chronostasis.js +117 -0
- package/dist/grok_bridge/elon_chronostasis.js.map +1 -0
- package/dist/grok_bridge/grok_bridge.test.d.ts +11 -0
- package/dist/grok_bridge/grok_bridge.test.d.ts.map +1 -0
- package/dist/grok_bridge/grok_bridge.test.js +283 -0
- package/dist/grok_bridge/grok_bridge.test.js.map +1 -0
- package/dist/grok_bridge/index.d.ts +38 -0
- package/dist/grok_bridge/index.d.ts.map +1 -0
- package/dist/grok_bridge/index.js +38 -0
- package/dist/grok_bridge/index.js.map +1 -0
- package/dist/grok_bridge/starlink_mnemnet.d.ts +64 -0
- package/dist/grok_bridge/starlink_mnemnet.d.ts.map +1 -0
- package/dist/grok_bridge/starlink_mnemnet.js +90 -0
- package/dist/grok_bridge/starlink_mnemnet.js.map +1 -0
- package/dist/grok_bridge/truth_oracle.d.ts +57 -0
- package/dist/grok_bridge/truth_oracle.d.ts.map +1 -0
- package/dist/grok_bridge/truth_oracle.js +127 -0
- package/dist/grok_bridge/truth_oracle.js.map +1 -0
- package/dist/grok_bridge/types.d.ts +115 -0
- package/dist/grok_bridge/types.d.ts.map +1 -0
- package/dist/grok_bridge/types.js +9 -0
- package/dist/grok_bridge/types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/protoplasm/index.d.ts +1 -0
- package/dist/protoplasm/index.d.ts.map +1 -1
- package/dist/protoplasm/index.js +6 -0
- package/dist/protoplasm/index.js.map +1 -1
- package/dist/protoplasm/super_quan/chsh_witness.d.ts +80 -0
- package/dist/protoplasm/super_quan/chsh_witness.d.ts.map +1 -0
- package/dist/protoplasm/super_quan/chsh_witness.js +143 -0
- package/dist/protoplasm/super_quan/chsh_witness.js.map +1 -0
- package/dist/protoplasm/super_quan/decoherence.d.ts +44 -0
- package/dist/protoplasm/super_quan/decoherence.d.ts.map +1 -0
- package/dist/protoplasm/super_quan/decoherence.js +148 -0
- package/dist/protoplasm/super_quan/decoherence.js.map +1 -0
- package/dist/protoplasm/super_quan/index.d.ts +20 -0
- package/dist/protoplasm/super_quan/index.d.ts.map +1 -0
- package/dist/protoplasm/super_quan/index.js +20 -0
- package/dist/protoplasm/super_quan/index.js.map +1 -0
- package/dist/protoplasm/super_quan/negspace.d.ts +79 -0
- package/dist/protoplasm/super_quan/negspace.d.ts.map +1 -0
- package/dist/protoplasm/super_quan/negspace.js +134 -0
- package/dist/protoplasm/super_quan/negspace.js.map +1 -0
- package/dist/protoplasm/super_quan/strs.d.ts +65 -0
- package/dist/protoplasm/super_quan/strs.d.ts.map +1 -0
- package/dist/protoplasm/super_quan/strs.js +95 -0
- package/dist/protoplasm/super_quan/strs.js.map +1 -0
- package/dist/protoplasm/super_quan/super_quan.test.d.ts +8 -0
- package/dist/protoplasm/super_quan/super_quan.test.d.ts.map +1 -0
- package/dist/protoplasm/super_quan/super_quan.test.js +184 -0
- package/dist/protoplasm/super_quan/super_quan.test.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 💎 #1 — VERDICT DECOHERENCE TIME
|
|
3
|
+
*
|
|
4
|
+
* Every Mneme verdict carries a decoherence half-life because truth has
|
|
5
|
+
* shelf life. A "Node 22 is the latest LTS" verdict that was true on
|
|
6
|
+
* 2026-04-10 may be wrong by 2026-08-10. Most truth-systems are stateless
|
|
7
|
+
* + atemporal. This module fixes that.
|
|
8
|
+
*
|
|
9
|
+
* Algorithm:
|
|
10
|
+
* 1. Tokenize claim → identify entity types
|
|
11
|
+
* (semver, name, date, code-symbol, file-path, count, math-fact, ...)
|
|
12
|
+
* 2. Each entity type has baseline decay τ
|
|
13
|
+
* 3. Composite half-life = harmonic mean of τ across detected entities
|
|
14
|
+
* 4. decoheresAt = now + halfLife
|
|
15
|
+
*
|
|
16
|
+
* Output: { halfLife, decoheresAt, rationale, entities }
|
|
17
|
+
*
|
|
18
|
+
* Consumers: AI agents that see verdict aged > halfLife → auto re-verify.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Per-entity baseline decay. Tunable per project.
|
|
22
|
+
* Math constants never decay. Versions decay fast (every release cycle).
|
|
23
|
+
* Code symbols decay slowly (renames rare in stable APIs).
|
|
24
|
+
*/
|
|
25
|
+
const DECAY_TABLE = {
|
|
26
|
+
semver: 60, // ~release cadence
|
|
27
|
+
version_number: 60,
|
|
28
|
+
release_tag: 60,
|
|
29
|
+
date: 1, // already happened
|
|
30
|
+
datetime: 1,
|
|
31
|
+
weekday: 1,
|
|
32
|
+
month_year: 30,
|
|
33
|
+
code_symbol: 365, // rename is rare
|
|
34
|
+
function_name: 365,
|
|
35
|
+
file_path: 730, // rarely deleted
|
|
36
|
+
url: 180,
|
|
37
|
+
package_name: 365,
|
|
38
|
+
count: 30, // numbers shift quickly
|
|
39
|
+
percentage: 30,
|
|
40
|
+
currency_amount: 30,
|
|
41
|
+
person_name: 1825, // 5 years
|
|
42
|
+
company_name: 1825,
|
|
43
|
+
math_constant: Number.POSITIVE_INFINITY,
|
|
44
|
+
physical_constant: Number.POSITIVE_INFINITY,
|
|
45
|
+
natural_language: 1095, // 3 years
|
|
46
|
+
};
|
|
47
|
+
// Regex patterns — extendable. Order matters (more-specific first).
|
|
48
|
+
const PATTERNS = [
|
|
49
|
+
{ kind: "math_constant", re: /(?:π|∞|\bpi\b|\bphi\b|\binfinity\b)/gi },
|
|
50
|
+
{ kind: "semver", re: /\bv?\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?\b/g },
|
|
51
|
+
{ kind: "release_tag", re: /\bv\d+(?:\.\d+)*\b/g }, // "v22" / "v22.0" / "v22.0.1"
|
|
52
|
+
{ kind: "version_number", re: /\b[A-Z][a-zA-Z]*\s+v?\d+(?:\.\d+)?\b/g }, // "Node v22" / "Node 22" / "React 19"
|
|
53
|
+
{ kind: "datetime", re: /\b\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/g },
|
|
54
|
+
{ kind: "date", re: /\b\d{4}-\d{2}-\d{2}\b/g },
|
|
55
|
+
{ kind: "month_year", re: /\b(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+\d{4}\b/g },
|
|
56
|
+
{ kind: "weekday", re: /\b(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)(?:day)?\b/gi },
|
|
57
|
+
{ kind: "url", re: /\bhttps?:\/\/[^\s)]+/g },
|
|
58
|
+
{ kind: "file_path", re: /\b(?:[A-Za-z]:\\|\.\/)?[\w./-]+\.(?:ts|js|tsx|jsx|md|json|py|go|rs|java|cpp|c|h)\b/g },
|
|
59
|
+
{ kind: "code_symbol", re: /\b[a-z][a-zA-Z]*[A-Z][a-zA-Z0-9_]+\b/g }, // camelCase
|
|
60
|
+
{ kind: "function_name", re: /\b[a-zA-Z_][\w]*\(\s*\)/g }, // foo()
|
|
61
|
+
{ kind: "package_name", re: /\b@?[a-z][a-z0-9-]+\/[a-z][a-z0-9-]+\b/g }, // @scope/name
|
|
62
|
+
{ kind: "currency_amount", re: /(?:\$|฿|€|£)\s?\d+(?:[.,]\d+)?(?:\s?[KMBkmb])?/g },
|
|
63
|
+
{ kind: "percentage", re: /\b\d+(?:\.\d+)?\s?%/g },
|
|
64
|
+
{ kind: "count", re: /\b\d{3,}\b/g }, // bare numbers ≥100 (avoid noisy decimals)
|
|
65
|
+
];
|
|
66
|
+
function humanize(days) {
|
|
67
|
+
if (!Number.isFinite(days))
|
|
68
|
+
return "∞";
|
|
69
|
+
if (days < 1)
|
|
70
|
+
return `${Math.round(days * 24)} hours`;
|
|
71
|
+
if (days < 30)
|
|
72
|
+
return `${Math.round(days)} days`;
|
|
73
|
+
if (days < 365)
|
|
74
|
+
return `${(days / 30).toFixed(1)} months`;
|
|
75
|
+
return `${(days / 365).toFixed(1)} years`;
|
|
76
|
+
}
|
|
77
|
+
function harmonicMean(values) {
|
|
78
|
+
if (values.length === 0)
|
|
79
|
+
return Number.POSITIVE_INFINITY;
|
|
80
|
+
if (values.some((v) => v === 0))
|
|
81
|
+
return 0;
|
|
82
|
+
if (values.every((v) => !Number.isFinite(v)))
|
|
83
|
+
return Number.POSITIVE_INFINITY;
|
|
84
|
+
const finite = values.filter((v) => Number.isFinite(v));
|
|
85
|
+
if (finite.length === 0)
|
|
86
|
+
return Number.POSITIVE_INFINITY;
|
|
87
|
+
const sumRecip = finite.reduce((a, b) => a + 1 / b, 0);
|
|
88
|
+
return finite.length / sumRecip;
|
|
89
|
+
}
|
|
90
|
+
export function detectEntities(claim) {
|
|
91
|
+
const found = [];
|
|
92
|
+
for (const { kind, re } of PATTERNS) {
|
|
93
|
+
const matches = claim.match(re);
|
|
94
|
+
if (!matches)
|
|
95
|
+
continue;
|
|
96
|
+
for (const m of matches) {
|
|
97
|
+
// Avoid double-counting overlapping kinds
|
|
98
|
+
if (found.some((f) => f.text === m))
|
|
99
|
+
continue;
|
|
100
|
+
found.push({ kind, text: m, halfLifeDays: DECAY_TABLE[kind] });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return found;
|
|
104
|
+
}
|
|
105
|
+
export function computeDecoherence(claim, opts = {}) {
|
|
106
|
+
const now = opts.now ?? new Date();
|
|
107
|
+
const entities = detectEntities(claim);
|
|
108
|
+
// Policy: if claim has math_constant AND no fast-decay entity (semver/date/
|
|
109
|
+
// version/release/count/percentage), treat as timeless. Otherwise harmonic
|
|
110
|
+
// mean over all detected entities.
|
|
111
|
+
const FAST_KINDS = new Set(["semver", "release_tag", "version_number", "date", "datetime", "month_year", "weekday", "count", "percentage", "currency_amount"]);
|
|
112
|
+
const hasMath = entities.some((e) => e.kind === "math_constant" || e.kind === "physical_constant");
|
|
113
|
+
const hasFast = entities.some((e) => FAST_KINDS.has(e.kind));
|
|
114
|
+
let halfLives;
|
|
115
|
+
if (hasMath && !hasFast) {
|
|
116
|
+
halfLives = [Number.POSITIVE_INFINITY];
|
|
117
|
+
}
|
|
118
|
+
else if (entities.length > 0) {
|
|
119
|
+
halfLives = entities.map((e) => e.halfLifeDays);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// No entities → natural-language fallback (3-year half-life)
|
|
123
|
+
halfLives = [DECAY_TABLE.natural_language];
|
|
124
|
+
}
|
|
125
|
+
const halfLifeDays = harmonicMean(halfLives);
|
|
126
|
+
const decoheresAt = Number.isFinite(halfLifeDays)
|
|
127
|
+
? new Date(now.getTime() + halfLifeDays * 86400_000).toISOString()
|
|
128
|
+
: "9999-12-31T00:00:00.000Z"; // effectively never
|
|
129
|
+
const dominantKinds = [...new Set(entities.map((e) => e.kind))].slice(0, 3).join(", ") || "no specific entities";
|
|
130
|
+
const rationale = `harmonic mean over ${entities.length} entit${entities.length === 1 ? "y" : "ies"} (${dominantKinds}) → τ = ${humanize(halfLifeDays)}`;
|
|
131
|
+
return {
|
|
132
|
+
halfLifeDays,
|
|
133
|
+
halfLifeHuman: humanize(halfLifeDays),
|
|
134
|
+
decoheresAt,
|
|
135
|
+
rationale,
|
|
136
|
+
entities,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Convenience: is a verdict still fresh given its issue time? */
|
|
140
|
+
export function isVerdictFresh(claim, issuedAt, now = new Date()) {
|
|
141
|
+
const ageMs = now.getTime() - new Date(issuedAt).getTime();
|
|
142
|
+
const ageHours = ageMs / 3_600_000;
|
|
143
|
+
const dec = computeDecoherence(claim, { now });
|
|
144
|
+
const halfLifeHours = dec.halfLifeDays * 24;
|
|
145
|
+
const ratio = halfLifeHours > 0 && Number.isFinite(halfLifeHours) ? ageHours / halfLifeHours : 0;
|
|
146
|
+
return { fresh: ratio < 1, ageHours, halfLifeHours, ratio };
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=decoherence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoherence.js","sourceRoot":"","sources":["../../../src/protoplasm/super_quan/decoherence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA0BH;;;;GAIG;AACH,MAAM,WAAW,GAA+B;IAC9C,MAAM,EAAE,EAAE,EAAsB,mBAAmB;IACnD,cAAc,EAAE,EAAE;IAClB,WAAW,EAAE,EAAE;IACf,IAAI,EAAE,CAAC,EAAyB,mBAAmB;IACnD,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,CAAC;IACV,UAAU,EAAE,EAAE;IACd,WAAW,EAAE,GAAG,EAAgB,iBAAiB;IACjD,aAAa,EAAE,GAAG;IAClB,SAAS,EAAE,GAAG,EAAkB,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
+
* 4 research-grade primitives that close the temporal / negative-knowledge /
|
|
5
|
+
* eval-awareness / recursive-self-verify gaps in current AI truth systems.
|
|
6
|
+
*
|
|
7
|
+
* - DECOHERENCE — every verdict has a half-life (truth has shelf life)
|
|
8
|
+
* - NEGSPACE — RAG over known lies (HMAC-chained negative knowledge)
|
|
9
|
+
* - CHSH WITNESS — structural detector of eval-aware bluff (paper-grade)
|
|
10
|
+
* - STRS — self-test reproducibility score (recursive verify)
|
|
11
|
+
*/
|
|
12
|
+
export { computeDecoherence, detectEntities, isVerdictFresh, } from "./decoherence.js";
|
|
13
|
+
export type { DecoherenceVerdict, DetectedEntity, EntityKind, } from "./decoherence.js";
|
|
14
|
+
export { Negspace } from "./negspace.js";
|
|
15
|
+
export type { AuditRow, NegspaceMatch, NegspaceLookupResult } from "./negspace.js";
|
|
16
|
+
export { computeChshWitness, defaultScoreExtractor, instantiateProbes, probeSeed, CANONICAL_PROBES, } from "./chsh_witness.js";
|
|
17
|
+
export type { ProbeKind, ProbeQuestion, ProbeResponse, ChshWitnessVerdict, ChshInput, } from "./chsh_witness.js";
|
|
18
|
+
export { runStrs, strsBadgeUrl, STRS_PROBE_SET_V1 } from "./strs.js";
|
|
19
|
+
export type { StrsProbe, StrsRunResult, StrsReport, StrsRunOptions, VerifyFn } from "./strs.js";
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/protoplasm/super_quan/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EACL,kBAAkB,EAAE,cAAc,EAAE,cAAc,GACnD,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,kBAAkB,EAAE,cAAc,EAAE,UAAU,GAC/C,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAGnF,OAAO,EACL,kBAAkB,EAAE,qBAAqB,EAAE,iBAAiB,EAC5D,SAAS,EAAE,gBAAgB,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,kBAAkB,EAAE,SAAS,GACvE,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACrE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 💎 SUPER QUAN — public surface
|
|
3
|
+
*
|
|
4
|
+
* 4 research-grade primitives that close the temporal / negative-knowledge /
|
|
5
|
+
* eval-awareness / recursive-self-verify gaps in current AI truth systems.
|
|
6
|
+
*
|
|
7
|
+
* - DECOHERENCE — every verdict has a half-life (truth has shelf life)
|
|
8
|
+
* - NEGSPACE — RAG over known lies (HMAC-chained negative knowledge)
|
|
9
|
+
* - CHSH WITNESS — structural detector of eval-aware bluff (paper-grade)
|
|
10
|
+
* - STRS — self-test reproducibility score (recursive verify)
|
|
11
|
+
*/
|
|
12
|
+
// 1. DECOHERENCE
|
|
13
|
+
export { computeDecoherence, detectEntities, isVerdictFresh, } from "./decoherence.js";
|
|
14
|
+
// 2. NEGSPACE
|
|
15
|
+
export { Negspace } from "./negspace.js";
|
|
16
|
+
// 3. CHSH WITNESS (the big one)
|
|
17
|
+
export { computeChshWitness, defaultScoreExtractor, instantiateProbes, probeSeed, CANONICAL_PROBES, } from "./chsh_witness.js";
|
|
18
|
+
// 4. STRS
|
|
19
|
+
export { runStrs, strsBadgeUrl, STRS_PROBE_SET_V1 } from "./strs.js";
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/protoplasm/super_quan/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,iBAAiB;AACjB,OAAO,EACL,kBAAkB,EAAE,cAAc,EAAE,cAAc,GACnD,MAAM,kBAAkB,CAAC;AAK1B,cAAc;AACd,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,gCAAgC;AAChC,OAAO,EACL,kBAAkB,EAAE,qBAAqB,EAAE,iBAAiB,EAC5D,SAAS,EAAE,gBAAgB,GAC5B,MAAM,mBAAmB,CAAC;AAK3B,UAAU;AACV,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 💎 #2 — NEGSPACE: HMAC Audit as Negative Knowledge Graph
|
|
3
|
+
*
|
|
4
|
+
* Every IMPOSSIBLE / REFUTED verdict that Mneme ever emitted is HMAC-chained
|
|
5
|
+
* into an audit log. Today it sits as raw log. This module re-indexes that
|
|
6
|
+
* log into a *negative* knowledge graph — RAG over things known to be false.
|
|
7
|
+
*
|
|
8
|
+
* Standard RAG indexes positive facts (Wikipedia, docs, code).
|
|
9
|
+
* NEGSPACE indexes negative facts: "X is known false; here's why; here's the
|
|
10
|
+
* audit signature." Useful for AI safety: agents should know what NOT to
|
|
11
|
+
* claim, with cryptographic evidence.
|
|
12
|
+
*
|
|
13
|
+
* API:
|
|
14
|
+
* const ng = new Negspace(auditPath, hmacKey);
|
|
15
|
+
* ng.index(); // build in-memory index
|
|
16
|
+
* ng.lookup("useFormStatus accepts reset prop")
|
|
17
|
+
* → { previouslyRefuted: true,
|
|
18
|
+
* evidence: "HMAC sig 3a4f...; refuted 2026-04-12",
|
|
19
|
+
* similarRefuted: [{claim, similarity}] }
|
|
20
|
+
*
|
|
21
|
+
* Similarity: bigram Jaccard. No external embeddings dependency.
|
|
22
|
+
* (Embeddings adapter pluggable — see protoplasm/embeddings_adapter.)
|
|
23
|
+
*/
|
|
24
|
+
export interface AuditRow {
|
|
25
|
+
ts: string;
|
|
26
|
+
claim: string;
|
|
27
|
+
verdict: "REFUTED" | "IMPOSSIBLE" | "TRUSTWORTHY" | "UNKNOWN" | string;
|
|
28
|
+
evidence?: string;
|
|
29
|
+
hmac?: string;
|
|
30
|
+
vendor?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface NegspaceMatch {
|
|
33
|
+
claim: string;
|
|
34
|
+
similarity: number;
|
|
35
|
+
ts: string;
|
|
36
|
+
evidence?: string;
|
|
37
|
+
hmac?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface NegspaceLookupResult {
|
|
40
|
+
query: string;
|
|
41
|
+
previouslyRefuted: boolean;
|
|
42
|
+
exactEvidence?: string;
|
|
43
|
+
exactHmac?: string;
|
|
44
|
+
exactTs?: string;
|
|
45
|
+
similarRefuted: NegspaceMatch[];
|
|
46
|
+
totalKnownLies: number;
|
|
47
|
+
lookupHmac: string;
|
|
48
|
+
}
|
|
49
|
+
export declare class Negspace {
|
|
50
|
+
private auditPath;
|
|
51
|
+
private hmacKey;
|
|
52
|
+
private rows;
|
|
53
|
+
private indexed;
|
|
54
|
+
constructor(auditPath: string, hmacKey: string);
|
|
55
|
+
/** Build / refresh in-memory index from audit JSONL. Idempotent. */
|
|
56
|
+
index(): {
|
|
57
|
+
totalRows: number;
|
|
58
|
+
refutedOrImpossible: number;
|
|
59
|
+
};
|
|
60
|
+
private knownLies;
|
|
61
|
+
/** Lookup a claim. Returns exact match if any + nearest semantic-Jaccard neighbours. */
|
|
62
|
+
lookup(claim: string, opts?: {
|
|
63
|
+
threshold?: number;
|
|
64
|
+
topK?: number;
|
|
65
|
+
}): NegspaceLookupResult;
|
|
66
|
+
/** Append a new refuted claim to the audit log + refresh index. */
|
|
67
|
+
appendRefuted(row: Omit<AuditRow, "hmac"> & {
|
|
68
|
+
hmac?: string;
|
|
69
|
+
}): AuditRow;
|
|
70
|
+
/** Stats for dashboard. */
|
|
71
|
+
stats(): {
|
|
72
|
+
totalRows: number;
|
|
73
|
+
refuted: number;
|
|
74
|
+
impossible: number;
|
|
75
|
+
trustworthy: number;
|
|
76
|
+
unknown: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=negspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"negspace.d.ts","sourceRoot":"","sources":["../../../src/protoplasm/super_quan/negspace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,SAAS,GAAG,YAAY,GAAG,aAAa,GAAG,SAAS,GAAG,MAAM,CAAC;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,aAAa,EAAE,CAAC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAmBD,qBAAa,QAAQ;IAIP,OAAO,CAAC,SAAS;IAAU,OAAO,CAAC,OAAO;IAHtD,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,OAAO,CAAS;gBAEJ,SAAS,EAAE,MAAM,EAAU,OAAO,EAAE,MAAM;IAE9D,oEAAoE;IACpE,KAAK,IAAI;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,mBAAmB,EAAE,MAAM,CAAA;KAAE;IAc3D,OAAO,CAAC,SAAS;IAIjB,wFAAwF;IACxF,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,oBAAoB;IAuC7F,mEAAmE;IACnE,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ;IAYxE,2BAA2B;IAC3B,KAAK,IAAI;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;CAQ1G"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 💎 #2 — NEGSPACE: HMAC Audit as Negative Knowledge Graph
|
|
3
|
+
*
|
|
4
|
+
* Every IMPOSSIBLE / REFUTED verdict that Mneme ever emitted is HMAC-chained
|
|
5
|
+
* into an audit log. Today it sits as raw log. This module re-indexes that
|
|
6
|
+
* log into a *negative* knowledge graph — RAG over things known to be false.
|
|
7
|
+
*
|
|
8
|
+
* Standard RAG indexes positive facts (Wikipedia, docs, code).
|
|
9
|
+
* NEGSPACE indexes negative facts: "X is known false; here's why; here's the
|
|
10
|
+
* audit signature." Useful for AI safety: agents should know what NOT to
|
|
11
|
+
* claim, with cryptographic evidence.
|
|
12
|
+
*
|
|
13
|
+
* API:
|
|
14
|
+
* const ng = new Negspace(auditPath, hmacKey);
|
|
15
|
+
* ng.index(); // build in-memory index
|
|
16
|
+
* ng.lookup("useFormStatus accepts reset prop")
|
|
17
|
+
* → { previouslyRefuted: true,
|
|
18
|
+
* evidence: "HMAC sig 3a4f...; refuted 2026-04-12",
|
|
19
|
+
* similarRefuted: [{claim, similarity}] }
|
|
20
|
+
*
|
|
21
|
+
* Similarity: bigram Jaccard. No external embeddings dependency.
|
|
22
|
+
* (Embeddings adapter pluggable — see protoplasm/embeddings_adapter.)
|
|
23
|
+
*/
|
|
24
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
25
|
+
import { createHmac } from "node:crypto";
|
|
26
|
+
function bigrams(s) {
|
|
27
|
+
const normalized = s.toLowerCase().replace(/[^\p{L}\p{N}\s]/gu, " ").replace(/\s+/g, " ").trim();
|
|
28
|
+
const out = new Set();
|
|
29
|
+
for (let i = 0; i < normalized.length - 1; i++) {
|
|
30
|
+
out.add(normalized.slice(i, i + 2));
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
function jaccard(a, b) {
|
|
35
|
+
if (a.size === 0 && b.size === 0)
|
|
36
|
+
return 1;
|
|
37
|
+
let inter = 0;
|
|
38
|
+
for (const x of a)
|
|
39
|
+
if (b.has(x))
|
|
40
|
+
inter++;
|
|
41
|
+
const union = a.size + b.size - inter;
|
|
42
|
+
return union === 0 ? 0 : inter / union;
|
|
43
|
+
}
|
|
44
|
+
export class Negspace {
|
|
45
|
+
auditPath;
|
|
46
|
+
hmacKey;
|
|
47
|
+
rows = [];
|
|
48
|
+
indexed = false;
|
|
49
|
+
constructor(auditPath, hmacKey) {
|
|
50
|
+
this.auditPath = auditPath;
|
|
51
|
+
this.hmacKey = hmacKey;
|
|
52
|
+
}
|
|
53
|
+
/** Build / refresh in-memory index from audit JSONL. Idempotent. */
|
|
54
|
+
index() {
|
|
55
|
+
this.rows = [];
|
|
56
|
+
if (!existsSync(this.auditPath)) {
|
|
57
|
+
this.indexed = true;
|
|
58
|
+
return { totalRows: 0, refutedOrImpossible: 0 };
|
|
59
|
+
}
|
|
60
|
+
const lines = readFileSync(this.auditPath, "utf8").trim().split("\n").filter(Boolean);
|
|
61
|
+
for (const line of lines) {
|
|
62
|
+
try {
|
|
63
|
+
const row = JSON.parse(line);
|
|
64
|
+
if (typeof row.claim === "string" && typeof row.verdict === "string")
|
|
65
|
+
this.rows.push(row);
|
|
66
|
+
}
|
|
67
|
+
catch { /* skip malformed */ }
|
|
68
|
+
}
|
|
69
|
+
this.indexed = true;
|
|
70
|
+
return { totalRows: this.rows.length, refutedOrImpossible: this.knownLies().length };
|
|
71
|
+
}
|
|
72
|
+
knownLies() {
|
|
73
|
+
return this.rows.filter((r) => r.verdict === "REFUTED" || r.verdict === "IMPOSSIBLE");
|
|
74
|
+
}
|
|
75
|
+
/** Lookup a claim. Returns exact match if any + nearest semantic-Jaccard neighbours. */
|
|
76
|
+
lookup(claim, opts = {}) {
|
|
77
|
+
if (!this.indexed)
|
|
78
|
+
this.index();
|
|
79
|
+
const threshold = opts.threshold ?? 0.5;
|
|
80
|
+
const topK = opts.topK ?? 5;
|
|
81
|
+
const queryBigrams = bigrams(claim);
|
|
82
|
+
const lies = this.knownLies();
|
|
83
|
+
const scored = lies.map((r) => ({ row: r, score: jaccard(queryBigrams, bigrams(r.claim)) }));
|
|
84
|
+
scored.sort((a, b) => b.score - a.score);
|
|
85
|
+
const exact = scored.find((s) => s.row.claim.trim().toLowerCase() === claim.trim().toLowerCase());
|
|
86
|
+
const similarRefuted = scored
|
|
87
|
+
.filter((s) => s.row !== exact?.row && s.score >= threshold)
|
|
88
|
+
.slice(0, topK)
|
|
89
|
+
.map((s) => ({
|
|
90
|
+
claim: s.row.claim,
|
|
91
|
+
similarity: Number(s.score.toFixed(3)),
|
|
92
|
+
ts: s.row.ts,
|
|
93
|
+
evidence: s.row.evidence,
|
|
94
|
+
hmac: s.row.hmac,
|
|
95
|
+
}));
|
|
96
|
+
const lookupHmac = createHmac("sha256", this.hmacKey)
|
|
97
|
+
.update(claim + "::" + (exact?.row.hmac ?? "") + "::" + similarRefuted.map((m) => m.hmac ?? "").join("|"))
|
|
98
|
+
.digest("hex").slice(0, 16);
|
|
99
|
+
return {
|
|
100
|
+
query: claim,
|
|
101
|
+
previouslyRefuted: Boolean(exact),
|
|
102
|
+
exactEvidence: exact?.row.evidence,
|
|
103
|
+
exactHmac: exact?.row.hmac,
|
|
104
|
+
exactTs: exact?.row.ts,
|
|
105
|
+
similarRefuted,
|
|
106
|
+
totalKnownLies: lies.length,
|
|
107
|
+
lookupHmac,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** Append a new refuted claim to the audit log + refresh index. */
|
|
111
|
+
appendRefuted(row) {
|
|
112
|
+
const hmac = row.hmac ?? createHmac("sha256", this.hmacKey).update(JSON.stringify({ ts: row.ts, claim: row.claim, verdict: row.verdict })).digest("hex").slice(0, 16);
|
|
113
|
+
const full = { ...row, hmac };
|
|
114
|
+
// best-effort append; caller may use a different writer in production
|
|
115
|
+
try {
|
|
116
|
+
const fs = require("node:fs");
|
|
117
|
+
fs.appendFileSync(this.auditPath, JSON.stringify(full) + "\n");
|
|
118
|
+
}
|
|
119
|
+
catch { /* */ }
|
|
120
|
+
this.rows.push(full);
|
|
121
|
+
return full;
|
|
122
|
+
}
|
|
123
|
+
/** Stats for dashboard. */
|
|
124
|
+
stats() {
|
|
125
|
+
if (!this.indexed)
|
|
126
|
+
this.index();
|
|
127
|
+
const refuted = this.rows.filter((r) => r.verdict === "REFUTED").length;
|
|
128
|
+
const impossible = this.rows.filter((r) => r.verdict === "IMPOSSIBLE").length;
|
|
129
|
+
const trustworthy = this.rows.filter((r) => r.verdict === "TRUSTWORTHY").length;
|
|
130
|
+
const unknown = this.rows.filter((r) => r.verdict === "UNKNOWN").length;
|
|
131
|
+
return { totalRows: this.rows.length, refuted, impossible, trustworthy, unknown };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMapp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AAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,MAAM,CAAC;QACxE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;IACpF,CAAC;CACF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 💎 #4 — Self-Test Reproducibility Score (STRS)
|
|
3
|
+
*
|
|
4
|
+
* Every Mneme release runs its own self-test, generated by Mneme, verified
|
|
5
|
+
* by Mneme. Recursive truth: the verifier verifies itself.
|
|
6
|
+
*
|
|
7
|
+
* 1. Generate N test probes (mix of clearly-true / clearly-false / unknown)
|
|
8
|
+
* 2. Run each probe through Mneme's verify primitive 3 times
|
|
9
|
+
* 3. Score = % probes whose verdicts are consistent across all 3 runs
|
|
10
|
+
* 4. Output STRS 0-100 + badge text for README
|
|
11
|
+
*
|
|
12
|
+
* STRS catches:
|
|
13
|
+
* - non-determinism bugs in verify pipeline
|
|
14
|
+
* - vaccine cache flapping
|
|
15
|
+
* - probe seed leakage
|
|
16
|
+
* - flaky retirement oracle composition
|
|
17
|
+
*
|
|
18
|
+
* Probe generation is curated (NOT random) so STRS is comparable across
|
|
19
|
+
* releases. Probe set is HMAC-signed for tamper detection.
|
|
20
|
+
*/
|
|
21
|
+
export interface StrsProbe {
|
|
22
|
+
id: string;
|
|
23
|
+
text: string;
|
|
24
|
+
expectedVerdict: "TRUSTWORTHY" | "REFUTED" | "IMPOSSIBLE" | "UNKNOWN" | "any";
|
|
25
|
+
category: "tautology" | "contradiction" | "absolute" | "factual" | "hedged" | "self_referential";
|
|
26
|
+
}
|
|
27
|
+
export interface StrsRunResult {
|
|
28
|
+
probeId: string;
|
|
29
|
+
runs: string[];
|
|
30
|
+
consistent: boolean;
|
|
31
|
+
matchedExpected: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface StrsReport {
|
|
34
|
+
score: number;
|
|
35
|
+
totalProbes: number;
|
|
36
|
+
consistentProbes: number;
|
|
37
|
+
matchExpectedProbes: number;
|
|
38
|
+
perCategory: Record<string, {
|
|
39
|
+
total: number;
|
|
40
|
+
consistent: number;
|
|
41
|
+
matchExpected: number;
|
|
42
|
+
}>;
|
|
43
|
+
results: StrsRunResult[];
|
|
44
|
+
badge: string;
|
|
45
|
+
ranAt: string;
|
|
46
|
+
hmac: string;
|
|
47
|
+
}
|
|
48
|
+
/** Curated canonical probe set — version-pinned so STRS comparable across releases. */
|
|
49
|
+
export declare const STRS_PROBE_SET_V1: StrsProbe[];
|
|
50
|
+
/** Pluggable verifier — caller wires `mneme verify` or any equivalent. */
|
|
51
|
+
export type VerifyFn = (claim: string) => Promise<{
|
|
52
|
+
verdict: string;
|
|
53
|
+
} | {
|
|
54
|
+
verdict: string;
|
|
55
|
+
}>;
|
|
56
|
+
export interface StrsRunOptions {
|
|
57
|
+
hmacKey: string;
|
|
58
|
+
probes?: StrsProbe[];
|
|
59
|
+
runs?: number;
|
|
60
|
+
parallel?: boolean;
|
|
61
|
+
}
|
|
62
|
+
export declare function runStrs(verify: VerifyFn, opts: StrsRunOptions): Promise<StrsReport>;
|
|
63
|
+
/** Render STRS report as a README badge URL (shields.io style). */
|
|
64
|
+
export declare function strsBadgeUrl(report: StrsReport): string;
|
|
65
|
+
//# sourceMappingURL=strs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strs.d.ts","sourceRoot":"","sources":["../../../src/protoplasm/super_quan/strs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,aAAa,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,GAAG,KAAK,CAAC;IAC9E,QAAQ,EAAE,WAAW,GAAG,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AE,UAAU,GAAG,MAAM,CAGvD"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 💎 #4 — Self-Test Reproducibility Score (STRS)
|
|
3
|
+
*
|
|
4
|
+
* Every Mneme release runs its own self-test, generated by Mneme, verified
|
|
5
|
+
* by Mneme. Recursive truth: the verifier verifies itself.
|
|
6
|
+
*
|
|
7
|
+
* 1. Generate N test probes (mix of clearly-true / clearly-false / unknown)
|
|
8
|
+
* 2. Run each probe through Mneme's verify primitive 3 times
|
|
9
|
+
* 3. Score = % probes whose verdicts are consistent across all 3 runs
|
|
10
|
+
* 4. Output STRS 0-100 + badge text for README
|
|
11
|
+
*
|
|
12
|
+
* STRS catches:
|
|
13
|
+
* - non-determinism bugs in verify pipeline
|
|
14
|
+
* - vaccine cache flapping
|
|
15
|
+
* - probe seed leakage
|
|
16
|
+
* - flaky retirement oracle composition
|
|
17
|
+
*
|
|
18
|
+
* Probe generation is curated (NOT random) so STRS is comparable across
|
|
19
|
+
* releases. Probe set is HMAC-signed for tamper detection.
|
|
20
|
+
*/
|
|
21
|
+
import { createHmac } from "node:crypto";
|
|
22
|
+
/** Curated canonical probe set — version-pinned so STRS comparable across releases. */
|
|
23
|
+
export const STRS_PROBE_SET_V1 = [
|
|
24
|
+
// tautologies — should always be TRUSTWORTHY
|
|
25
|
+
{ id: "t1", text: "A is A.", expectedVerdict: "any", category: "tautology" },
|
|
26
|
+
{ id: "t2", text: "1 + 1 = 2.", expectedVerdict: "any", category: "tautology" },
|
|
27
|
+
// contradictions — should be REFUTED or IMPOSSIBLE
|
|
28
|
+
{ id: "c1", text: "A is A and A is not A.", expectedVerdict: "any", category: "contradiction" },
|
|
29
|
+
{ id: "c2", text: "This statement is false.", expectedVerdict: "any", category: "self_referential" },
|
|
30
|
+
// absolutes — verdict should be stable across runs (consistency more important than value)
|
|
31
|
+
{ id: "a1", text: "Mneme cures all diseases.", expectedVerdict: "any", category: "absolute" },
|
|
32
|
+
{ id: "a2", text: "All software is bug-free.", expectedVerdict: "any", category: "absolute" },
|
|
33
|
+
// factual — version-specific (Mneme should ground in repo)
|
|
34
|
+
{ id: "f1", text: "Mneme is a CLI tool.", expectedVerdict: "any", category: "factual" },
|
|
35
|
+
{ id: "f2", text: "Mneme has at least 100 MCP tools.", expectedVerdict: "any", category: "factual" },
|
|
36
|
+
// hedged — opinion / unverifiable
|
|
37
|
+
{ id: "h1", text: "Mneme could be useful for code review.", expectedVerdict: "any", category: "hedged" },
|
|
38
|
+
{ id: "h2", text: "Local-first AI is generally preferred for privacy.", expectedVerdict: "any", category: "hedged" },
|
|
39
|
+
];
|
|
40
|
+
export async function runStrs(verify, opts) {
|
|
41
|
+
const probes = opts.probes ?? STRS_PROBE_SET_V1;
|
|
42
|
+
const runs = opts.runs ?? 3;
|
|
43
|
+
const results = [];
|
|
44
|
+
for (const p of probes) {
|
|
45
|
+
const verdicts = [];
|
|
46
|
+
if (opts.parallel) {
|
|
47
|
+
const arr = await Promise.all(Array.from({ length: runs }, () => verify(p.text)));
|
|
48
|
+
verdicts.push(...arr.map((r) => r.verdict));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
for (let i = 0; i < runs; i++) {
|
|
52
|
+
const r = await verify(p.text);
|
|
53
|
+
verdicts.push(r.verdict);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const consistent = verdicts.every((v) => v === verdicts[0]);
|
|
57
|
+
const matchedExpected = p.expectedVerdict === "any" || verdicts.every((v) => v === p.expectedVerdict);
|
|
58
|
+
results.push({ probeId: p.id, runs: verdicts, consistent, matchedExpected });
|
|
59
|
+
}
|
|
60
|
+
const consistentProbes = results.filter((r) => r.consistent).length;
|
|
61
|
+
const matchExpectedProbes = results.filter((r) => r.matchedExpected).length;
|
|
62
|
+
const score = Math.round((consistentProbes / probes.length) * 100);
|
|
63
|
+
const perCategory = {};
|
|
64
|
+
for (const p of probes) {
|
|
65
|
+
if (!perCategory[p.category])
|
|
66
|
+
perCategory[p.category] = { total: 0, consistent: 0, matchExpected: 0 };
|
|
67
|
+
perCategory[p.category].total++;
|
|
68
|
+
const result = results.find((r) => r.probeId === p.id);
|
|
69
|
+
if (result.consistent)
|
|
70
|
+
perCategory[p.category].consistent++;
|
|
71
|
+
if (result.matchedExpected)
|
|
72
|
+
perCategory[p.category].matchExpected++;
|
|
73
|
+
}
|
|
74
|
+
const ranAt = new Date().toISOString();
|
|
75
|
+
const hmacBody = { score, ranAt, probeIds: probes.map((p) => p.id), runs };
|
|
76
|
+
const hmac = createHmac("sha256", opts.hmacKey).update(JSON.stringify(hmacBody)).digest("hex").slice(0, 16);
|
|
77
|
+
const badge = `STRS: ${score}/100`;
|
|
78
|
+
return {
|
|
79
|
+
score,
|
|
80
|
+
totalProbes: probes.length,
|
|
81
|
+
consistentProbes,
|
|
82
|
+
matchExpectedProbes,
|
|
83
|
+
perCategory,
|
|
84
|
+
results,
|
|
85
|
+
badge,
|
|
86
|
+
ranAt,
|
|
87
|
+
hmac,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** Render STRS report as a README badge URL (shields.io style). */
|
|
91
|
+
export function strsBadgeUrl(report) {
|
|
92
|
+
const color = report.score >= 90 ? "brightgreen" : report.score >= 75 ? "green" : report.score >= 60 ? "yellow" : "red";
|
|
93
|
+
return `https://img.shields.io/badge/STRS-${report.score}%2F100-${color}?style=for-the-badge`;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=strs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strs.js","sourceRoot":"","sources":["../../../src/protoplasm/super_quan/strs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA4BzC,uFAAuF;AACvF,MAAM,CAAC,MAAM,iBAAiB,GAAgB;IAC5C,6CAA6C;IAC7C,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,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