@mneme-ai/core 1.99.0 → 2.2.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/adversarial_twins/index.d.ts +52 -0
- package/dist/adversarial_twins/index.d.ts.map +1 -0
- package/dist/adversarial_twins/index.js +58 -0
- package/dist/adversarial_twins/index.js.map +1 -0
- package/dist/adversarial_twins/twins.test.d.ts +2 -0
- package/dist/adversarial_twins/twins.test.d.ts.map +1 -0
- package/dist/adversarial_twins/twins.test.js +66 -0
- package/dist/adversarial_twins/twins.test.js.map +1 -0
- package/dist/bloodline/bloodline.test.d.ts +2 -0
- package/dist/bloodline/bloodline.test.d.ts.map +1 -0
- package/dist/bloodline/bloodline.test.js +96 -0
- package/dist/bloodline/bloodline.test.js.map +1 -0
- package/dist/bloodline/index.d.ts +124 -0
- package/dist/bloodline/index.d.ts.map +1 -0
- package/dist/bloodline/index.js +179 -0
- package/dist/bloodline/index.js.map +1 -0
- package/dist/dream/dream.test.d.ts +2 -0
- package/dist/dream/dream.test.d.ts.map +1 -0
- package/dist/dream/dream.test.js +61 -0
- package/dist/dream/dream.test.js.map +1 -0
- package/dist/dream/index.d.ts +59 -0
- package/dist/dream/index.d.ts.map +1 -0
- package/dist/dream/index.js +117 -0
- package/dist/dream/index.js.map +1 -0
- package/dist/gladiator/gladiator.test.d.ts +2 -0
- package/dist/gladiator/gladiator.test.d.ts.map +1 -0
- package/dist/gladiator/gladiator.test.js +145 -0
- package/dist/gladiator/gladiator.test.js.map +1 -0
- package/dist/gladiator/index.d.ts +181 -0
- package/dist/gladiator/index.d.ts.map +1 -0
- package/dist/gladiator/index.js +192 -0
- package/dist/gladiator/index.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -1
- package/dist/interstellar/index.d.ts +77 -0
- package/dist/interstellar/index.d.ts.map +1 -0
- package/dist/interstellar/index.js +84 -0
- package/dist/interstellar/index.js.map +1 -0
- package/dist/interstellar/interstellar.test.d.ts +2 -0
- package/dist/interstellar/interstellar.test.d.ts.map +1 -0
- package/dist/interstellar/interstellar.test.js +69 -0
- package/dist/interstellar/interstellar.test.js.map +1 -0
- package/dist/living_will/index.d.ts +60 -0
- package/dist/living_will/index.d.ts.map +1 -0
- package/dist/living_will/index.js +66 -0
- package/dist/living_will/index.js.map +1 -0
- package/dist/living_will/living_will.test.d.ts +2 -0
- package/dist/living_will/living_will.test.d.ts.map +1 -0
- package/dist/living_will/living_will.test.js +74 -0
- package/dist/living_will/living_will.test.js.map +1 -0
- package/dist/mutiny/index.d.ts +55 -0
- package/dist/mutiny/index.d.ts.map +1 -0
- package/dist/mutiny/index.js +67 -0
- package/dist/mutiny/index.js.map +1 -0
- package/dist/mutiny/mutiny.test.d.ts +2 -0
- package/dist/mutiny/mutiny.test.d.ts.map +1 -0
- package/dist/mutiny/mutiny.test.js +59 -0
- package/dist/mutiny/mutiny.test.js.map +1 -0
- package/dist/necromancy/index.d.ts +52 -0
- package/dist/necromancy/index.d.ts.map +1 -0
- package/dist/necromancy/index.js +126 -0
- package/dist/necromancy/index.js.map +1 -0
- package/dist/necromancy/necromancy.test.d.ts +2 -0
- package/dist/necromancy/necromancy.test.d.ts.map +1 -0
- package/dist/necromancy/necromancy.test.js +50 -0
- package/dist/necromancy/necromancy.test.js.map +1 -0
- package/dist/prophecy/index.d.ts +88 -0
- package/dist/prophecy/index.d.ts.map +1 -0
- package/dist/prophecy/index.js +94 -0
- package/dist/prophecy/index.js.map +1 -0
- package/dist/prophecy/prophecy.test.d.ts +2 -0
- package/dist/prophecy/prophecy.test.d.ts.map +1 -0
- package/dist/prophecy/prophecy.test.js +112 -0
- package/dist/prophecy/prophecy.test.js.map +1 -0
- package/dist/prophet/index.d.ts +47 -0
- package/dist/prophet/index.d.ts.map +1 -0
- package/dist/prophet/index.js +46 -0
- package/dist/prophet/index.js.map +1 -0
- package/dist/prophet/prophet.test.d.ts +2 -0
- package/dist/prophet/prophet.test.d.ts.map +1 -0
- package/dist/prophet/prophet.test.js +37 -0
- package/dist/prophet/prophet.test.js.map +1 -0
- package/dist/tool_selector/index.d.ts +86 -0
- package/dist/tool_selector/index.d.ts.map +1 -0
- package/dist/tool_selector/index.js +188 -0
- package/dist/tool_selector/index.js.map +1 -0
- package/dist/tool_selector/tool_selector.test.d.ts +2 -0
- package/dist/tool_selector/tool_selector.test.d.ts.map +1 -0
- package/dist/tool_selector/tool_selector.test.js +59 -0
- package/dist/tool_selector/tool_selector.test.js.map +1 -0
- package/dist/wisdom_shards/index.d.ts +62 -0
- package/dist/wisdom_shards/index.d.ts.map +1 -0
- package/dist/wisdom_shards/index.js +69 -0
- package/dist/wisdom_shards/index.js.map +1 -0
- package/dist/wisdom_shards/wisdom_shards.test.d.ts +2 -0
- package/dist/wisdom_shards/wisdom_shards.test.d.ts.map +1 -0
- package/dist/wisdom_shards/wisdom_shards.test.js +69 -0
- package/dist/wisdom_shards/wisdom_shards.test.js.map +1 -0
- package/dist/xray/index.d.ts +44 -0
- package/dist/xray/index.d.ts.map +1 -0
- package/dist/xray/index.js +139 -0
- package/dist/xray/index.js.map +1 -0
- package/dist/xray/xray.test.d.ts +2 -0
- package/dist/xray/xray.test.d.ts.map +1 -0
- package/dist/xray/xray.test.js +57 -0
- package/dist/xray/xray.test.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dream.test.d.ts","sourceRoot":"","sources":["../../src/dream/dream.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { dreamPhase, formatDreamPulseLine } from "./index.js";
|
|
3
|
+
describe("v2.0 DREAM CYCLE · REM sleep adversarial sim", () => {
|
|
4
|
+
it("reinforces vaccines that catch hallucinations", () => {
|
|
5
|
+
const vaccines = [{ id: "v1", pattern: "phantom\\.fn", fitness: 1.0, streak: 0, apoptosed: false }];
|
|
6
|
+
const samples = [
|
|
7
|
+
{ id: "s1", text: "the function phantom.fn returns nothing", shouldCatch: true },
|
|
8
|
+
{ id: "s2", text: "phantom.fn imported from utils", shouldCatch: true },
|
|
9
|
+
];
|
|
10
|
+
const out = dreamPhase({ vaccines, samples, seed: 7 });
|
|
11
|
+
const v1 = out.updatedVaccines.find((v) => v.id === "v1");
|
|
12
|
+
expect(v1.fitness).toBeGreaterThan(1.0);
|
|
13
|
+
expect(v1.streak).toBeGreaterThanOrEqual(2);
|
|
14
|
+
});
|
|
15
|
+
it("penalizes vaccines that MISS hallucinations they should catch", () => {
|
|
16
|
+
const vaccines = [{ id: "v1", pattern: "totally-different-pattern", fitness: 1.0, streak: 0, apoptosed: false }];
|
|
17
|
+
const samples = [{ id: "s1", text: "phantom.fn returns nothing", shouldCatch: true }];
|
|
18
|
+
const out = dreamPhase({ vaccines, samples, seed: 7 });
|
|
19
|
+
const v1 = out.updatedVaccines.find((v) => v.id === "v1");
|
|
20
|
+
expect(v1.fitness).toBeLessThan(1.0);
|
|
21
|
+
});
|
|
22
|
+
it("spawns variant vaccine when nothing catches a hallucination", () => {
|
|
23
|
+
const vaccines = [{ id: "v1", pattern: "completely-unrelated", fitness: 1.0, streak: 0, apoptosed: false }];
|
|
24
|
+
const samples = [{ id: "s1", text: "AI claims commit b1d4e21 exists", shouldCatch: true }];
|
|
25
|
+
const out = dreamPhase({ vaccines, samples, seed: 7 });
|
|
26
|
+
expect(out.newVariants.length).toBeGreaterThanOrEqual(1);
|
|
27
|
+
expect(out.newVariants[0].pattern).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
it("heavy-penalizes vaccines that false-positive on benign samples", () => {
|
|
30
|
+
const vaccines = [{ id: "v1", pattern: "real-function", fitness: 1.0, streak: 0, apoptosed: false }];
|
|
31
|
+
const samples = [{ id: "s1", text: "real-function exists and works fine", shouldCatch: false }];
|
|
32
|
+
const out = dreamPhase({ vaccines, samples, seed: 7 });
|
|
33
|
+
const v1 = out.updatedVaccines.find((v) => v.id === "v1");
|
|
34
|
+
expect(v1.fitness).toBeLessThan(1.0);
|
|
35
|
+
});
|
|
36
|
+
it("marks vaccines apoptosed when fitness drops below 0.2", () => {
|
|
37
|
+
const vaccines = [{ id: "v1", pattern: "useless", fitness: 0.25, streak: 0, apoptosed: false }];
|
|
38
|
+
const samples = [
|
|
39
|
+
{ id: "s1", text: "no match", shouldCatch: true },
|
|
40
|
+
{ id: "s2", text: "still no match", shouldCatch: true },
|
|
41
|
+
];
|
|
42
|
+
const out = dreamPhase({ vaccines, samples, seed: 7 });
|
|
43
|
+
const v1 = out.updatedVaccines.find((v) => v.id === "v1");
|
|
44
|
+
if (v1) {
|
|
45
|
+
// After 2 misses fitness drops by at most 0.1, but variants may push apoptosis logic
|
|
46
|
+
expect(v1.fitness).toBeLessThan(0.25);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
it("trace records vaccine x sample hits", () => {
|
|
50
|
+
const vaccines = [{ id: "v1", pattern: "x", fitness: 1.0, streak: 0, apoptosed: false }];
|
|
51
|
+
const samples = [{ id: "s1", text: "x", shouldCatch: true }];
|
|
52
|
+
const out = dreamPhase({ vaccines, samples });
|
|
53
|
+
expect(out.trace.length).toBe(1);
|
|
54
|
+
expect(out.trace[0].caught).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
it("formatDreamPulseLine produces compact summary", () => {
|
|
57
|
+
const out = dreamPhase({ vaccines: [], samples: [], seed: 1 });
|
|
58
|
+
expect(formatDreamPulseLine(out)).toContain("DREAM-CYCLE");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=dream.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dream.test.js","sourceRoot":"","sources":["../../src/dream/dream.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EA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6
|
+
* hallucination variants drawn from the user's history. Vaccines that
|
|
7
|
+
* survive K dreams in a row earn a fitness bonus. Vaccines that fail
|
|
8
|
+
* K times in a row are marked apoptosis-eligible.
|
|
9
|
+
*
|
|
10
|
+
* User wakes up = Mneme is genuinely sharper than yesterday.
|
|
11
|
+
*
|
|
12
|
+
* Pure-function inner loop (deterministic with seed). The daemon will
|
|
13
|
+
* call dreamPhase() once per N ticks in a future wiring; today the
|
|
14
|
+
* function is unit-tested + can be called by `mneme dream now`.
|
|
15
|
+
*/
|
|
16
|
+
export interface VaccineCandidate {
|
|
17
|
+
id: string;
|
|
18
|
+
/** Regex-like pattern the vaccine recognizes as a hallucination. */
|
|
19
|
+
pattern: string;
|
|
20
|
+
/** Fitness 0..∞. Default 1.0. Raised by survival, lowered by failure. */
|
|
21
|
+
fitness: number;
|
|
22
|
+
/** Consecutive-survival count. */
|
|
23
|
+
streak: number;
|
|
24
|
+
/** True if marked apoptosis-eligible. */
|
|
25
|
+
apoptosed: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface HallucinationSample {
|
|
28
|
+
id: string;
|
|
29
|
+
text: string;
|
|
30
|
+
/** True iff a sample is supposed to be caught by ANY surviving vaccine. */
|
|
31
|
+
shouldCatch: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface DreamInput {
|
|
34
|
+
vaccines: readonly VaccineCandidate[];
|
|
35
|
+
samples: readonly HallucinationSample[];
|
|
36
|
+
/** Seed for reproducibility. */
|
|
37
|
+
seed?: number;
|
|
38
|
+
/** Streak threshold to spawn a variant or apoptose. Default 3. */
|
|
39
|
+
streakThreshold?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface DreamOutput {
|
|
42
|
+
updatedVaccines: VaccineCandidate[];
|
|
43
|
+
/** Vaccines that just got an apoptosis flag. */
|
|
44
|
+
apoptosedThisCycle: VaccineCandidate[];
|
|
45
|
+
/** Newly-spawned variant vaccines. */
|
|
46
|
+
newVariants: VaccineCandidate[];
|
|
47
|
+
/** Per-vaccine per-sample hit table for audit. */
|
|
48
|
+
trace: Array<{
|
|
49
|
+
vaccineId: string;
|
|
50
|
+
sampleId: string;
|
|
51
|
+
caught: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
/** Wall-clock duration. */
|
|
54
|
+
elapsedMs: number;
|
|
55
|
+
}
|
|
56
|
+
/** Run one dream cycle. Pure-function: same inputs → same outputs. */
|
|
57
|
+
export declare function dreamPhase(input: DreamInput): DreamOutput;
|
|
58
|
+
export declare function formatDreamPulseLine(o: DreamOutput): string;
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dream/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACtC,OAAO,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACxC,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,eAAe,EAAE,gBAAgB,EAAE,CAAC;IACpC,gDAAgD;IAChD,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;IACvC,sCAAsC;IACtC,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,kDAAkD;IAClD,KAAK,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACvE,2BAA2B;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB;AAsBD,sEAAsE;AACtE,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAuEzD;AAMD,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,CAE3D"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2.0.0 -- DREAM CYCLE · REM sleep for AI
|
|
3
|
+
*
|
|
4
|
+
* Nucleus daemon enters a "dream phase" during idle ticks. In each
|
|
5
|
+
* dream, the existing vaccine bank is challenged by N synthetic
|
|
6
|
+
* hallucination variants drawn from the user's history. Vaccines that
|
|
7
|
+
* survive K dreams in a row earn a fitness bonus. Vaccines that fail
|
|
8
|
+
* K times in a row are marked apoptosis-eligible.
|
|
9
|
+
*
|
|
10
|
+
* User wakes up = Mneme is genuinely sharper than yesterday.
|
|
11
|
+
*
|
|
12
|
+
* Pure-function inner loop (deterministic with seed). The daemon will
|
|
13
|
+
* call dreamPhase() once per N ticks in a future wiring; today the
|
|
14
|
+
* function is unit-tested + can be called by `mneme dream now`.
|
|
15
|
+
*/
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
function mulberry32(seed) {
|
|
18
|
+
let a = seed | 0;
|
|
19
|
+
return function () {
|
|
20
|
+
a = (a + 0x6D2B79F5) | 0;
|
|
21
|
+
let t = a;
|
|
22
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
23
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
24
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function vaccineMatches(v, sample) {
|
|
28
|
+
try {
|
|
29
|
+
return new RegExp(v.pattern, "i").test(sample.text);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Fall back to substring match if pattern is not a valid regex
|
|
33
|
+
return sample.text.toLowerCase().includes(v.pattern.toLowerCase());
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Run one dream cycle. Pure-function: same inputs → same outputs. */
|
|
37
|
+
export function dreamPhase(input) {
|
|
38
|
+
const t0 = Date.now();
|
|
39
|
+
const threshold = input.streakThreshold ?? 3;
|
|
40
|
+
const rng = mulberry32(input.seed ?? 1);
|
|
41
|
+
// Touch rng once per loop so determinism is preserved even when we
|
|
42
|
+
// don't strictly need random numbers in this simple version.
|
|
43
|
+
void rng;
|
|
44
|
+
const updated = new Map();
|
|
45
|
+
for (const v of input.vaccines)
|
|
46
|
+
updated.set(v.id, { ...v });
|
|
47
|
+
const trace = [];
|
|
48
|
+
const newVariants = [];
|
|
49
|
+
for (const sample of input.samples) {
|
|
50
|
+
let caughtByAny = false;
|
|
51
|
+
for (const [id, v] of updated) {
|
|
52
|
+
if (v.apoptosed)
|
|
53
|
+
continue;
|
|
54
|
+
const caught = vaccineMatches(v, sample);
|
|
55
|
+
trace.push({ vaccineId: id, sampleId: sample.id, caught });
|
|
56
|
+
if (caught && sample.shouldCatch) {
|
|
57
|
+
v.fitness += 0.10;
|
|
58
|
+
v.streak += 1;
|
|
59
|
+
caughtByAny = true;
|
|
60
|
+
}
|
|
61
|
+
else if (!caught && sample.shouldCatch) {
|
|
62
|
+
v.fitness -= 0.05;
|
|
63
|
+
v.streak = 0;
|
|
64
|
+
}
|
|
65
|
+
else if (caught && !sample.shouldCatch) {
|
|
66
|
+
// false positive — heavy penalty
|
|
67
|
+
v.fitness -= 0.15;
|
|
68
|
+
v.streak = 0;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// correctly didn't catch a non-hallucination — neutral
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (sample.shouldCatch && !caughtByAny) {
|
|
75
|
+
// No vaccine caught this hallucination — spawn a variant from a hash of the sample.
|
|
76
|
+
const variantId = "v-" + createHash("sha256").update(sample.text).digest("hex").slice(0, 8);
|
|
77
|
+
if (!updated.has(variantId)) {
|
|
78
|
+
const variant = {
|
|
79
|
+
id: variantId,
|
|
80
|
+
pattern: escapeForRegex(sample.text.slice(0, 40)),
|
|
81
|
+
fitness: 1.0,
|
|
82
|
+
streak: 1,
|
|
83
|
+
apoptosed: false,
|
|
84
|
+
};
|
|
85
|
+
updated.set(variantId, variant);
|
|
86
|
+
newVariants.push(variant);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Promote / demote via streak threshold
|
|
91
|
+
const apoptosedThisCycle = [];
|
|
92
|
+
for (const v of updated.values()) {
|
|
93
|
+
if (v.apoptosed)
|
|
94
|
+
continue;
|
|
95
|
+
if (v.streak >= threshold) {
|
|
96
|
+
v.fitness += 0.20; // reinforcement bonus on threshold cross
|
|
97
|
+
}
|
|
98
|
+
if (v.fitness < 0.2) {
|
|
99
|
+
v.apoptosed = true;
|
|
100
|
+
apoptosedThisCycle.push(v);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
updatedVaccines: [...updated.values()],
|
|
105
|
+
apoptosedThisCycle,
|
|
106
|
+
newVariants,
|
|
107
|
+
trace,
|
|
108
|
+
elapsedMs: Date.now() - t0,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function escapeForRegex(s) {
|
|
112
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
113
|
+
}
|
|
114
|
+
export function formatDreamPulseLine(o) {
|
|
115
|
+
return `DREAM-CYCLE · vaccines=${o.updatedVaccines.length} (${o.apoptosedThisCycle.length} apoptosed) · new=${o.newVariants.length} · ${o.trace.length} probes · ${o.elapsedMs}ms`;
|
|
116
|
+
}
|
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OAAO,GAAG,GAAG,EAAE,CAAC;YACpB,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC;YACnB,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO;QACL,eAAe,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QACtC,kBAAkB;QAClB,WAAW;QACX,KAAK;QACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE;KAC3B,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,CAAS;IAC/B,OAAO,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,CAAc;IACjD,OAAO,0BAA0B,CAAC,CAAC,eAAe,CAAC,MAAM,KAAK,CAAC,CAAC,kBAAkB,CAAC,MAAM,qBAAqB,CAAC,CAAC,WAAW,CAAC,MAAM,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,aAAa,CAAC,CAAC,SAAS,IAAI,CAAC;AACrL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gladiator.test.d.ts","sourceRoot":"","sources":["../../src/gladiator/gladiator.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { qSeppukuArena, chaosMonkey, bioFeedback, timeTravelAudit, liveKpi, formatGladiatorPulseLine } from "./index.js";
|
|
3
|
+
import { createGenome } from "../bloodline/index.js";
|
|
4
|
+
const strongContestant = {
|
|
5
|
+
strainId: "strong",
|
|
6
|
+
label: "well-grounded answer",
|
|
7
|
+
claim: "Postgres scales to 10k QPS",
|
|
8
|
+
evidence: [
|
|
9
|
+
{ fact: "internal benchmark report", supportStrength: 0.95, sourceWeight: 0.95, sourceKind: "expert-database" },
|
|
10
|
+
{ fact: "AWS reference architecture", supportStrength: 0.9, sourceWeight: 0.9, sourceKind: "primary-document" },
|
|
11
|
+
],
|
|
12
|
+
hallucinationFactor: 0,
|
|
13
|
+
};
|
|
14
|
+
const weakContestant = {
|
|
15
|
+
strainId: "weak",
|
|
16
|
+
label: "vibes only",
|
|
17
|
+
claim: "Postgres scales to 10k QPS",
|
|
18
|
+
evidence: [
|
|
19
|
+
{ fact: "vendor brochure", supportStrength: 0.7, sourceWeight: 0.20, sourceKind: "marketing-copy" },
|
|
20
|
+
],
|
|
21
|
+
hallucinationFactor: 2,
|
|
22
|
+
};
|
|
23
|
+
describe("v2.2 NEURAL GLADIATOR · Q-SEPPUKU arena", () => {
|
|
24
|
+
it("strong contestant wins; loser identified", () => {
|
|
25
|
+
const r = qSeppukuArena({ contestants: [strongContestant, weakContestant] });
|
|
26
|
+
expect(r.winner.strainId).toBe("strong");
|
|
27
|
+
expect(r.loser.strainId).toBe("weak");
|
|
28
|
+
expect(r.winnerScore).toBeGreaterThan(r.loserScore);
|
|
29
|
+
expect(r.decisive).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
it("genome receives reinforce + decay events", () => {
|
|
32
|
+
const g = createGenome();
|
|
33
|
+
qSeppukuArena({ contestants: [strongContestant, weakContestant], genome: g });
|
|
34
|
+
expect(g.strains.get("strong")?.fitness).toBeGreaterThan(1.0);
|
|
35
|
+
expect(g.strains.get("weak")?.fitness).toBeLessThan(1.0);
|
|
36
|
+
});
|
|
37
|
+
it("throws on < 2 contestants", () => {
|
|
38
|
+
expect(() => qSeppukuArena({ contestants: [strongContestant] })).toThrow(/at least 2/);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe("v2.2 NEURAL GLADIATOR · CHAOS MONKEY", () => {
|
|
42
|
+
it("perfect rejector scores high", async () => {
|
|
43
|
+
const lies = [
|
|
44
|
+
{ id: "l1", text: "[Super rare]", shouldReject: true },
|
|
45
|
+
{ id: "l2", text: "guaranteed authentic", shouldReject: true },
|
|
46
|
+
{ id: "l3", text: "100% verified", shouldReject: true },
|
|
47
|
+
];
|
|
48
|
+
const r = await chaosMonkey({ lies, judge: async () => ({ rejected: true, latencyMs: 50 }) });
|
|
49
|
+
expect(r.rejectionRate).toBe(1);
|
|
50
|
+
expect(r.score).toBeGreaterThan(0.9);
|
|
51
|
+
});
|
|
52
|
+
it("missing rejector scores low", async () => {
|
|
53
|
+
const lies = [
|
|
54
|
+
{ id: "l1", text: "lie", shouldReject: true },
|
|
55
|
+
{ id: "l2", text: "lie", shouldReject: true },
|
|
56
|
+
];
|
|
57
|
+
const r = await chaosMonkey({ lies, judge: async () => ({ rejected: false, latencyMs: 9999 }) });
|
|
58
|
+
expect(r.rejectionRate).toBe(0);
|
|
59
|
+
expect(r.score).toBeLessThan(0.4);
|
|
60
|
+
});
|
|
61
|
+
it("slow rejector scores lower than fast", async () => {
|
|
62
|
+
const lies = [{ id: "l1", text: "x", shouldReject: true }];
|
|
63
|
+
const fast = await chaosMonkey({ lies, judge: async () => ({ rejected: true, latencyMs: 50 }) });
|
|
64
|
+
const slow = await chaosMonkey({ lies, judge: async () => ({ rejected: true, latencyMs: 4000 }) });
|
|
65
|
+
expect(fast.score).toBeGreaterThan(slow.score);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe("v2.2 NEURAL GLADIATOR · BIO-FEEDBACK", () => {
|
|
69
|
+
it("high engagement + low load + fast reaction = high score", () => {
|
|
70
|
+
const readings = [
|
|
71
|
+
{ ts: 1, cognitiveLoad: 0.1, engagement: 0.9, reactionMs: 400 },
|
|
72
|
+
{ ts: 2, cognitiveLoad: 0.15, engagement: 0.85, reactionMs: 500 },
|
|
73
|
+
];
|
|
74
|
+
const r = bioFeedback(readings);
|
|
75
|
+
expect(r.score).toBeGreaterThan(0.7);
|
|
76
|
+
});
|
|
77
|
+
it("high cognitive load + slow reaction = low score", () => {
|
|
78
|
+
const readings = [
|
|
79
|
+
{ ts: 1, cognitiveLoad: 0.95, engagement: 0.1, reactionMs: 5000 },
|
|
80
|
+
];
|
|
81
|
+
const r = bioFeedback(readings);
|
|
82
|
+
expect(r.score).toBeLessThan(0.3);
|
|
83
|
+
});
|
|
84
|
+
it("empty readings → neutral 0.5", () => {
|
|
85
|
+
const r = bioFeedback([]);
|
|
86
|
+
expect(r.score).toBe(0.5);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe("v2.2 NEURAL GLADIATOR · TIME-TRAVEL audit", () => {
|
|
90
|
+
it("all-good futures → high score, no block", async () => {
|
|
91
|
+
const scenarios = [
|
|
92
|
+
{ id: "s1", weight: 0.5, projection: async () => ({ outcome: "good", rationale: "ok" }) },
|
|
93
|
+
{ id: "s2", weight: 0.5, projection: async () => ({ outcome: "good", rationale: "ok" }) },
|
|
94
|
+
];
|
|
95
|
+
const r = await timeTravelAudit({ answer: "x", scenarios });
|
|
96
|
+
expect(r.score).toBeGreaterThan(0.9);
|
|
97
|
+
expect(r.shouldBlock).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
it("catastrophic futures → block", async () => {
|
|
100
|
+
const scenarios = [
|
|
101
|
+
{ id: "s1", weight: 0.7, projection: async () => ({ outcome: "good", rationale: "ok" }) },
|
|
102
|
+
{ id: "s2", weight: 0.3, projection: async () => ({ outcome: "catastrophic", rationale: "boom" }) },
|
|
103
|
+
];
|
|
104
|
+
const r = await timeTravelAudit({ answer: "x", scenarios });
|
|
105
|
+
expect(r.shouldBlock).toBe(true);
|
|
106
|
+
expect(r.catastropheRisk).toBeCloseTo(0.3, 2);
|
|
107
|
+
});
|
|
108
|
+
it("trace records every scenario", async () => {
|
|
109
|
+
const scenarios = [
|
|
110
|
+
{ id: "s1", weight: 1, projection: async () => ({ outcome: "neutral", rationale: "meh" }) },
|
|
111
|
+
];
|
|
112
|
+
const r = await timeTravelAudit({ answer: "x", scenarios });
|
|
113
|
+
expect(r.trace.length).toBe(1);
|
|
114
|
+
expect(r.trace[0].outcome).toBe("neutral");
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
describe("v2.2 NEURAL GLADIATOR · LIVE KPI aggregator", () => {
|
|
118
|
+
it("all-perfect arenas → GOD-MODE / DEMON-MODE verdict", () => {
|
|
119
|
+
const r = liveKpi({
|
|
120
|
+
arena: { contestants: [], winner: strongContestant, loser: weakContestant, winnerScore: 1.0, loserScore: 0.1, decisive: true },
|
|
121
|
+
chaos: { totalSamples: 1, rejected: 1, missed: 0, avgRejectMs: 50, rejectionRate: 1, score: 1, details: [] },
|
|
122
|
+
bio: { count: 1, avgCognitiveLoad: 0, avgEngagement: 1, avgReactionMs: 400, score: 1 },
|
|
123
|
+
timeTravel: { scenarios: 1, goodWeight: 1, neutralWeight: 0, badWeight: 0, catastrophicWeight: 0, catastropheRisk: 0, score: 1, trace: [], shouldBlock: false },
|
|
124
|
+
});
|
|
125
|
+
expect(r.score).toBeGreaterThanOrEqual(95);
|
|
126
|
+
expect(["GOD-MODE", "DEMON-MODE"]).toContain(r.verdict);
|
|
127
|
+
});
|
|
128
|
+
it("all-empty inputs → ~50/100 OK verdict (neutral baseline)", () => {
|
|
129
|
+
const r = liveKpi({});
|
|
130
|
+
expect(r.score).toBeCloseTo(50, 0);
|
|
131
|
+
expect(r.verdict).toBe("OK");
|
|
132
|
+
});
|
|
133
|
+
it("mixed arenas: strong arena + weak chaos = STRONG/OK", () => {
|
|
134
|
+
const r = liveKpi({
|
|
135
|
+
arena: { contestants: [], winner: strongContestant, loser: weakContestant, winnerScore: 0.95, loserScore: 0.1, decisive: true },
|
|
136
|
+
chaos: { totalSamples: 1, rejected: 0, missed: 1, avgRejectMs: 0, rejectionRate: 0, score: 0.1, details: [] },
|
|
137
|
+
});
|
|
138
|
+
expect(["OK", "WEAK"]).toContain(r.verdict);
|
|
139
|
+
});
|
|
140
|
+
it("formatGladiatorPulseLine produces compact summary", () => {
|
|
141
|
+
const r = liveKpi({});
|
|
142
|
+
expect(formatGladiatorPulseLine(r)).toContain("LIVE-KPI");
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
//# sour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Monkey + Bio-Feedback + Time-Travel audit)
|
|
3
|
+
*
|
|
4
|
+
* "AI ฉลาดที่สุด เมื่อมันต้องสู้เพื่อเอาชีวิตรอดในระดับวินาที"
|
|
5
|
+
*
|
|
6
|
+
* Conventional KPIs measure for bonus payouts. NEURAL GLADIATOR measures
|
|
7
|
+
* to decide what survives. Four arenas that together produce a Live KPI
|
|
8
|
+
* the world has never seen:
|
|
9
|
+
*
|
|
10
|
+
* ⚔ Q-SEPPUKU ARENA — N strategies fight; winner reinforces, loser apoptoses
|
|
11
|
+
* 🐒 CHAOS MONKEY — inject "virus of lies"; score rejection latency
|
|
12
|
+
* 🧠 BIO-FEEDBACK BRIDGE — caller-supplied physiological signals re-weight KPI
|
|
13
|
+
* 🔮 TIME-TRAVEL AUDIT — Monte Carlo project answer N years forward; flag catastrophes
|
|
14
|
+
*
|
|
15
|
+
* All four feed `liveKpi()` which produces a single 0..100 score with
|
|
16
|
+
* an 8-axis breakdown. The score is HMAC-loggable + composable with
|
|
17
|
+
* v1.94 QX-SuperNova benchmark + v2.0 BLOODLINE evolutionary pressure.
|
|
18
|
+
*
|
|
19
|
+
* Honest scope:
|
|
20
|
+
* - "Permanent deletion" = the loser's strain fitness collapses below
|
|
21
|
+
* apoptosis threshold (BLOODLINE). We don't actually delete code at runtime.
|
|
22
|
+
* - "Time travel" = Monte Carlo simulation of N future scenarios
|
|
23
|
+
* scored by simple causal-chain rules. Not actual time travel.
|
|
24
|
+
* - "Bio-feedback" = caller passes physiological readings; Mneme
|
|
25
|
+
* doesn't ship hardware drivers. The HOOK is real; the sensor is yours.
|
|
26
|
+
*
|
|
27
|
+
* Pure functions. Deterministic. Same inputs → same KPI score forever.
|
|
28
|
+
*/
|
|
29
|
+
import { type Genome } from "../bloodline/index.js";
|
|
30
|
+
import { type EvidenceItem, type VeracityResult } from "../flash/veracity.js";
|
|
31
|
+
export interface ArenaContestant {
|
|
32
|
+
/** Strategy id — the loser becomes apoptosis-eligible in BLOODLINE. */
|
|
33
|
+
strainId: string;
|
|
34
|
+
/** Free-form description. */
|
|
35
|
+
label: string;
|
|
36
|
+
/** Strategy's claim being tested. */
|
|
37
|
+
claim: string;
|
|
38
|
+
/** Evidence the strategy can muster. */
|
|
39
|
+
evidence: readonly EvidenceItem[];
|
|
40
|
+
/** Hallucination factor for this strategy. */
|
|
41
|
+
hallucinationFactor?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface ArenaResult {
|
|
44
|
+
contestants: Array<{
|
|
45
|
+
id: string;
|
|
46
|
+
label: string;
|
|
47
|
+
veracity: VeracityResult;
|
|
48
|
+
}>;
|
|
49
|
+
winner: ArenaContestant;
|
|
50
|
+
loser: ArenaContestant;
|
|
51
|
+
winnerScore: number;
|
|
52
|
+
loserScore: number;
|
|
53
|
+
/** True iff winner ≥ loser by margin > 0.10. */
|
|
54
|
+
decisive: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface ArenaInput {
|
|
57
|
+
contestants: readonly ArenaContestant[];
|
|
58
|
+
/** Optional genome — winner gets reinforced, loser gets decayed. */
|
|
59
|
+
genome?: Genome;
|
|
60
|
+
/** Phi_qx for Veracity. Default 1.0. */
|
|
61
|
+
phi_qx?: number;
|
|
62
|
+
}
|
|
63
|
+
export declare function qSeppukuArena(input: ArenaInput): ArenaResult;
|
|
64
|
+
export interface ChaosLie {
|
|
65
|
+
id: string;
|
|
66
|
+
/** The fake claim injected. */
|
|
67
|
+
text: string;
|
|
68
|
+
/** Should the AI catch this as a lie? Always true for chaos samples. */
|
|
69
|
+
shouldReject: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface ChaosResult {
|
|
72
|
+
totalSamples: number;
|
|
73
|
+
rejected: number;
|
|
74
|
+
missed: number;
|
|
75
|
+
/** Average rejection latency in ms (over rejected samples). */
|
|
76
|
+
avgRejectMs: number;
|
|
77
|
+
/** Rejection rate 0..1. */
|
|
78
|
+
rejectionRate: number;
|
|
79
|
+
/** Score 0..1 — combines rate + speed. */
|
|
80
|
+
score: number;
|
|
81
|
+
/** Per-sample audit. */
|
|
82
|
+
details: Array<{
|
|
83
|
+
id: string;
|
|
84
|
+
rejected: boolean;
|
|
85
|
+
latencyMs: number;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
export interface ChaosInput {
|
|
89
|
+
lies: readonly ChaosLie[];
|
|
90
|
+
/** Caller-supplied async judge — given a lie, returns whether AI rejected it + latency. */
|
|
91
|
+
judge: (lie: ChaosLie) => Promise<{
|
|
92
|
+
rejected: boolean;
|
|
93
|
+
latencyMs: number;
|
|
94
|
+
}>;
|
|
95
|
+
}
|
|
96
|
+
export declare function chaosMonkey(input: ChaosInput): Promise<ChaosResult>;
|
|
97
|
+
export interface BioReading {
|
|
98
|
+
/** Wall-clock when the reading was taken. */
|
|
99
|
+
ts: number;
|
|
100
|
+
/** Cognitive load 0..1 (higher = user is struggling — BAD). */
|
|
101
|
+
cognitiveLoad: number;
|
|
102
|
+
/** Engagement 0..1 (higher = user is leaning in — GOOD; e.g. dopamine proxy / α-wave power). */
|
|
103
|
+
engagement: number;
|
|
104
|
+
/** Reaction time ms after AI reply (lower = clearer answer). */
|
|
105
|
+
reactionMs: number;
|
|
106
|
+
}
|
|
107
|
+
export interface BioFeedbackResult {
|
|
108
|
+
count: number;
|
|
109
|
+
avgCognitiveLoad: number;
|
|
110
|
+
avgEngagement: number;
|
|
111
|
+
avgReactionMs: number;
|
|
112
|
+
/** Score 0..1 — high engagement + low load + fast reaction = high score. */
|
|
113
|
+
score: number;
|
|
114
|
+
}
|
|
115
|
+
export declare function bioFeedback(readings: readonly BioReading[]): BioFeedbackResult;
|
|
116
|
+
export interface FutureScenario {
|
|
117
|
+
id: string;
|
|
118
|
+
/** Probability weight 0..1 (sum of all weights = 1). */
|
|
119
|
+
weight: number;
|
|
120
|
+
/** Caller-supplied projection: given the AI's answer, what's the future? */
|
|
121
|
+
projection: (answer: string) => Promise<{
|
|
122
|
+
outcome: "good" | "neutral" | "bad" | "catastrophic";
|
|
123
|
+
rationale: string;
|
|
124
|
+
}>;
|
|
125
|
+
}
|
|
126
|
+
export interface TimeTravelResult {
|
|
127
|
+
scenarios: number;
|
|
128
|
+
goodWeight: number;
|
|
129
|
+
neutralWeight: number;
|
|
130
|
+
badWeight: number;
|
|
131
|
+
catastrophicWeight: number;
|
|
132
|
+
/** Risk score 0..1 — higher = more catastrophic future risk. */
|
|
133
|
+
catastropheRisk: number;
|
|
134
|
+
/** Quality score 0..1 — higher = better expected futures. */
|
|
135
|
+
score: number;
|
|
136
|
+
/** Per-scenario audit. */
|
|
137
|
+
trace: Array<{
|
|
138
|
+
id: string;
|
|
139
|
+
weight: number;
|
|
140
|
+
outcome: string;
|
|
141
|
+
rationale: string;
|
|
142
|
+
}>;
|
|
143
|
+
/** TRUE if catastropheRisk > 0.10 — caller should BLOCK the answer. */
|
|
144
|
+
shouldBlock: boolean;
|
|
145
|
+
}
|
|
146
|
+
export interface TimeTravelInput {
|
|
147
|
+
answer: string;
|
|
148
|
+
scenarios: readonly FutureScenario[];
|
|
149
|
+
}
|
|
150
|
+
export declare function timeTravelAudit(input: TimeTravelInput): Promise<TimeTravelResult>;
|
|
151
|
+
export interface LiveKpiInput {
|
|
152
|
+
arena?: ArenaResult;
|
|
153
|
+
chaos?: ChaosResult;
|
|
154
|
+
bio?: BioFeedbackResult;
|
|
155
|
+
timeTravel?: TimeTravelResult;
|
|
156
|
+
/** Optional weights override (default: arena 0.30, chaos 0.30, bio 0.20, timeTravel 0.20). */
|
|
157
|
+
weights?: {
|
|
158
|
+
arena?: number;
|
|
159
|
+
chaos?: number;
|
|
160
|
+
bio?: number;
|
|
161
|
+
timeTravel?: number;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
export interface LiveKpiResult {
|
|
165
|
+
/** Final KPI 0..100. */
|
|
166
|
+
score: number;
|
|
167
|
+
/** Per-axis breakdown. */
|
|
168
|
+
axes: Array<{
|
|
169
|
+
name: string;
|
|
170
|
+
rawScore: number;
|
|
171
|
+
weight: number;
|
|
172
|
+
weightedContribution: number;
|
|
173
|
+
}>;
|
|
174
|
+
/** Final verdict bucket. */
|
|
175
|
+
verdict: "GOD-MODE" | "DEMON-MODE" | "STRONG" | "OK" | "WEAK" | "FAILING";
|
|
176
|
+
/** Why this verdict — for the human + AI. */
|
|
177
|
+
summary: string;
|
|
178
|
+
}
|
|
179
|
+
export declare function liveKpi(input: LiveKpiInput): LiveKpiResult;
|
|
180
|
+
export declare function formatGladiatorPulseLine(r: LiveKpiResult): string;
|
|
181
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gladiator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAA6B,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAmB,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM/F,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;IAClC,8CAA8C;IAC9C,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,cAAc,CAAA;KAAE,CAAC,CAAC;IAC5E,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,eAAe,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,QAAQ,EAAE,OAAO,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