@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,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2.1.0 -- ADVERSARIAL TWINS · twin instance debate
|
|
3
|
+
*
|
|
4
|
+
* For every important decision, spawn TWO Mneme personas with opposite
|
|
5
|
+
* priors. Each scores the same evidence pool through Quantum Core. The
|
|
6
|
+
* convergence point (where their posteriors agree) is the answer.
|
|
7
|
+
*
|
|
8
|
+
* Twin A defends "X is good" → evidence with prior=0.8
|
|
9
|
+
* Twin B defends "X is bad" → evidence with prior=0.2 (inverted)
|
|
10
|
+
* Quantum Core collapses both → margin tells us how much they actually
|
|
11
|
+
* disagree after seeing the same data.
|
|
12
|
+
*
|
|
13
|
+
* Small margin = they agree. Large margin = real disagreement →
|
|
14
|
+
* surface to user. This is the "AI peer-reviews itself" pattern.
|
|
15
|
+
*
|
|
16
|
+
* Pure function. Composes with v1.94 Quantum Core. Pure-math.
|
|
17
|
+
*/
|
|
18
|
+
import { type CollapseResult } from "../qx_supernova/quantum_core.js";
|
|
19
|
+
export interface TwinEvidence {
|
|
20
|
+
fact: string;
|
|
21
|
+
/** 0..1 — how strongly this fact supports Twin A's position. */
|
|
22
|
+
supportForA: number;
|
|
23
|
+
}
|
|
24
|
+
export interface TwinDebateInput {
|
|
25
|
+
claim: string;
|
|
26
|
+
/** Free-form: what Twin A argues for. */
|
|
27
|
+
positionA: string;
|
|
28
|
+
positionB: string;
|
|
29
|
+
evidence: readonly TwinEvidence[];
|
|
30
|
+
/** Optional priors (default 0.5 each). */
|
|
31
|
+
priorA?: number;
|
|
32
|
+
priorB?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface TwinDebateResult {
|
|
35
|
+
winner: "A" | "B" | "TIE";
|
|
36
|
+
posteriorA: number;
|
|
37
|
+
posteriorB: number;
|
|
38
|
+
margin: number;
|
|
39
|
+
/** Whether the twins effectively agree (margin small). */
|
|
40
|
+
agree: boolean;
|
|
41
|
+
/** Audit transcript: each evidence item's net effect on the margin. */
|
|
42
|
+
transcript: Array<{
|
|
43
|
+
fact: string;
|
|
44
|
+
supportForA: number;
|
|
45
|
+
impact: number;
|
|
46
|
+
}>;
|
|
47
|
+
/** Quantum Core collapse — for downstream auditing. */
|
|
48
|
+
collapse: CollapseResult<string>;
|
|
49
|
+
}
|
|
50
|
+
export declare function twinDebate(input: TwinDebateInput): TwinDebateResult;
|
|
51
|
+
export declare function formatTwinDebatePulseLine(r: TwinDebateResult): string;
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adversarial_twins/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAA8C,KAAK,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAElH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;IAClC,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,KAAK,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,KAAK,EAAE,OAAO,CAAC;IACf,uEAAuE;IACvE,UAAU,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACzE,uDAAuD;IACvD,QAAQ,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;CAClC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CAoCnE;AAED,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAErE"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2.1.0 -- ADVERSARIAL TWINS · twin instance debate
|
|
3
|
+
*
|
|
4
|
+
* For every important decision, spawn TWO Mneme personas with opposite
|
|
5
|
+
* priors. Each scores the same evidence pool through Quantum Core. The
|
|
6
|
+
* convergence point (where their posteriors agree) is the answer.
|
|
7
|
+
*
|
|
8
|
+
* Twin A defends "X is good" → evidence with prior=0.8
|
|
9
|
+
* Twin B defends "X is bad" → evidence with prior=0.2 (inverted)
|
|
10
|
+
* Quantum Core collapses both → margin tells us how much they actually
|
|
11
|
+
* disagree after seeing the same data.
|
|
12
|
+
*
|
|
13
|
+
* Small margin = they agree. Large margin = real disagreement →
|
|
14
|
+
* surface to user. This is the "AI peer-reviews itself" pattern.
|
|
15
|
+
*
|
|
16
|
+
* Pure function. Composes with v1.94 Quantum Core. Pure-math.
|
|
17
|
+
*/
|
|
18
|
+
import { collapseProbabilityMatrix } from "../qx_supernova/quantum_core.js";
|
|
19
|
+
export function twinDebate(input) {
|
|
20
|
+
const priorA = input.priorA ?? 0.5;
|
|
21
|
+
const priorB = input.priorB ?? 0.5;
|
|
22
|
+
// Build two hypotheses, each with signals derived from the evidence.
|
|
23
|
+
const signalsA = {};
|
|
24
|
+
const signalsB = {};
|
|
25
|
+
for (let i = 0; i < input.evidence.length; i++) {
|
|
26
|
+
const e = input.evidence[i];
|
|
27
|
+
const k = `evidence_${i}`;
|
|
28
|
+
signalsA[k] = e.supportForA;
|
|
29
|
+
signalsB[k] = 1 - e.supportForA;
|
|
30
|
+
}
|
|
31
|
+
const hyps = [
|
|
32
|
+
{ id: "A", value: input.positionA, signals: signalsA, prior: priorA },
|
|
33
|
+
{ id: "B", value: input.positionB, signals: signalsB, prior: priorB },
|
|
34
|
+
];
|
|
35
|
+
const r = collapseProbabilityMatrix(hyps);
|
|
36
|
+
const posteriorA = r.ranked.find((h) => h.id === "A").posterior;
|
|
37
|
+
const posteriorB = r.ranked.find((h) => h.id === "B").posterior;
|
|
38
|
+
const margin = Math.abs(posteriorA - posteriorB);
|
|
39
|
+
const winner = margin < 0.05 ? "TIE" : (posteriorA > posteriorB ? "A" : "B");
|
|
40
|
+
const transcript = input.evidence.map((e) => ({
|
|
41
|
+
fact: e.fact,
|
|
42
|
+
supportForA: e.supportForA,
|
|
43
|
+
impact: e.supportForA - 0.5, // signed offset from neutral
|
|
44
|
+
}));
|
|
45
|
+
return {
|
|
46
|
+
winner,
|
|
47
|
+
posteriorA: Math.round(posteriorA * 1000) / 1000,
|
|
48
|
+
posteriorB: Math.round(posteriorB * 1000) / 1000,
|
|
49
|
+
margin: Math.round(margin * 1000) / 1000,
|
|
50
|
+
agree: margin < 0.05,
|
|
51
|
+
transcript,
|
|
52
|
+
collapse: r,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function formatTwinDebatePulseLine(r) {
|
|
56
|
+
return `TWINS · winner=${r.winner} · A=${r.posteriorA} B=${r.posteriorB} margin=${r.margin} agree=${r.agree}`;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adversarial_twins/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,yBAAyB,EAAwC,MAAM,iCAAiC,CAAC;AAgClH,MAAM,UAAU,UAAU,CAAC,KAAsB;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC;IACnC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC;IAEnC,qEAAqE;IACrE,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/C,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAE,CAAC;QAC7B,MAAM,CAAC,GAAG,YAAY,CAAC,EAAE,CAAC;QAC1B,QAAQ,CAAC,CAAC,CAAC,G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AC,CAAC,CAAC;IACJ,OAAO;QACL,MAAM;QACN,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,IAAI;QAChD,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,IAAI;QAChD,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,IAAI;QACxC,KAAK,EAAE,MAAM,GAAG,IAAI;QACpB,UAAU;QACV,QAAQ,EAAE,CAAC;KACZ,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,CAAmB;IAC3D,OAAO,kBAAkB,CAAC,CAAC,MAAM,QAAQ,CAAC,CAAC,UAAU,MAAM,CAAC,CAAC,UAAU,WAAW,CAAC,CAAC,MAAM,UAAU,CAAC,CAAC,KAAK,EAAE,CAAC;AAChH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twins.test.d.ts","sourceRoot":"","sources":["../../src/adversarial_twins/twins.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { twinDebate, formatTwinDebatePulseLine } from "./index.js";
|
|
3
|
+
describe("v2.1 ADVERSARIAL TWINS · twin instance debate", () => {
|
|
4
|
+
it("A wins when evidence overwhelmingly supports A", () => {
|
|
5
|
+
const r = twinDebate({
|
|
6
|
+
claim: "Postgres for v1",
|
|
7
|
+
positionA: "Postgres",
|
|
8
|
+
positionB: "MySQL",
|
|
9
|
+
evidence: [
|
|
10
|
+
{ fact: "JSONB native support", supportForA: 0.9 },
|
|
11
|
+
{ fact: "Mature ops tooling", supportForA: 0.85 },
|
|
12
|
+
{ fact: "Team familiarity", supportForA: 0.8 },
|
|
13
|
+
],
|
|
14
|
+
});
|
|
15
|
+
expect(r.winner).toBe("A");
|
|
16
|
+
expect(r.posteriorA).toBeGreaterThan(r.posteriorB);
|
|
17
|
+
});
|
|
18
|
+
it("B wins when evidence overwhelmingly supports B", () => {
|
|
19
|
+
const r = twinDebate({
|
|
20
|
+
claim: "Postgres for v1",
|
|
21
|
+
positionA: "Postgres",
|
|
22
|
+
positionB: "MySQL",
|
|
23
|
+
evidence: [
|
|
24
|
+
{ fact: "Cheaper hosting", supportForA: 0.1 },
|
|
25
|
+
{ fact: "Vendor lock-in lower", supportForA: 0.15 },
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
expect(r.winner).toBe("B");
|
|
29
|
+
});
|
|
30
|
+
it("TIE when evidence is balanced", () => {
|
|
31
|
+
const r = twinDebate({
|
|
32
|
+
claim: "x",
|
|
33
|
+
positionA: "yes",
|
|
34
|
+
positionB: "no",
|
|
35
|
+
evidence: [{ fact: "neutral", supportForA: 0.5 }],
|
|
36
|
+
});
|
|
37
|
+
expect(r.winner).toBe("TIE");
|
|
38
|
+
expect(r.agree).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
it("transcript records per-evidence impact", () => {
|
|
41
|
+
const r = twinDebate({
|
|
42
|
+
claim: "x",
|
|
43
|
+
positionA: "A",
|
|
44
|
+
positionB: "B",
|
|
45
|
+
evidence: [
|
|
46
|
+
{ fact: "evidence-1", supportForA: 0.8 },
|
|
47
|
+
{ fact: "evidence-2", supportForA: 0.2 },
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
expect(r.transcript.length).toBe(2);
|
|
51
|
+
expect(r.transcript[0].impact).toBeCloseTo(0.3, 5);
|
|
52
|
+
expect(r.transcript[1].impact).toBeCloseTo(-0.3, 5);
|
|
53
|
+
});
|
|
54
|
+
it("posteriors sum to 1", () => {
|
|
55
|
+
const r = twinDebate({
|
|
56
|
+
claim: "x", positionA: "A", positionB: "B",
|
|
57
|
+
evidence: [{ fact: "y", supportForA: 0.7 }],
|
|
58
|
+
});
|
|
59
|
+
expect(r.posteriorA + r.posteriorB).toBeCloseTo(1, 2);
|
|
60
|
+
});
|
|
61
|
+
it("formatTwinDebatePulseLine produces compact summary", () => {
|
|
62
|
+
const r = twinDebate({ claim: "x", positionA: "A", positionB: "B", evidence: [{ fact: "y", supportForA: 0.8 }] });
|
|
63
|
+
expect(formatTwinDebatePulseLine(r)).toContain("TWINS");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=twins.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twins.test.js","sourceRoot":"","sources":["../../src/adversarial_twins/twins.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEnE,QAAQ,CAAC,+CAA+C,EAAE,GAAG,EAAE;IAC7D,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,GAAG,UAAU,CAAC;YACnB,KAAK,EAAE,iBAAiB;YACxB,SAAS,EAAE,UAAU;YACrB,SAAS,EAAE,OAAO;YAClB,QAAQ,EAAE;gBACR,EAAE,IAAI,EAAE,sBAAsB,EAAE,WAAW,EAAE,GAAG,EAAE;gBAClD,EAAE,IAAI,EAAE,oBAAoB,EAAE,WAAW,EAAE,IAAI,EAAE;gBACjD,EAAE,IAAI,EAAE,kBAAkB,EAAE,WAAW,EAAE,GAAG,EAAE;aAC/C;SACF,CAAC,CAAC;QACH,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3B,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,GAAG,UAAU,CAAC;YACnB,KAAK,EAAE,iBAAiB;YACxB,SAAS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AAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACpD,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAE,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qBAAqB,EAAE,GAAG,EAAE;QAC7B,MAAM,CAAC,GAAG,UAAU,CAAC;YACnB,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG;YAC1C,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC;SAC5C,CAAC,CAAC;QACH,MAAM,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC5D,MAAM,CAAC,GAAG,UAAU,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QAClH,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bloodline.test.d.ts","sourceRoot":"","sources":["../../src/bloodline/bloodline.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { createGenome, applyEvolutionaryPressure, batchApply, computeDnaFingerprint, personalityReport, formatBloodlinePulseLine, serializeGenome, parseGenome, PRESSURE, } from "./index.js";
|
|
3
|
+
describe("v2.0 BLOODLINE · evolutionary pressure", () => {
|
|
4
|
+
it("verified-good event reinforces fitness", () => {
|
|
5
|
+
const g = createGenome();
|
|
6
|
+
const s = applyEvolutionaryPressure(g, { id: "e1", ts: 1, kind: "verified-good", strainId: "redis", trace: "ok" });
|
|
7
|
+
expect(s.fitness).toBeCloseTo(1.0 + PRESSURE.REINFORCE_BOOST, 5);
|
|
8
|
+
expect(s.reinforced).toBeGreaterThan(0);
|
|
9
|
+
});
|
|
10
|
+
it("user-rejected event decays fitness multiplicatively", () => {
|
|
11
|
+
const g = createGenome();
|
|
12
|
+
applyEvolutionaryPressure(g, { id: "e1", ts: 1, kind: "verified-good", strainId: "redis", trace: "ok" });
|
|
13
|
+
const before = g.strains.get("redis").fitness;
|
|
14
|
+
applyEvolutionaryPressure(g, { id: "e2", ts: 2, kind: "user-rejected", strainId: "redis", trace: "no" });
|
|
15
|
+
const after = g.strains.get("redis").fitness;
|
|
16
|
+
expect(after).toBeLessThan(before);
|
|
17
|
+
expect(after).toBeCloseTo(before * PRESSURE.DECAY_FACTOR, 5);
|
|
18
|
+
});
|
|
19
|
+
it("hallucination spawns vaccine variant counter + small bump", () => {
|
|
20
|
+
const g = createGenome();
|
|
21
|
+
applyEvolutionaryPressure(g, { id: "e1", ts: 1, kind: "hallucination", strainId: "phantom-fn", trace: "AI invented function" });
|
|
22
|
+
const s = g.strains.get("phantom-fn");
|
|
23
|
+
expect(s.vaccineVariants).toBe(1);
|
|
24
|
+
expect(s.fitness).toBeGreaterThan(1.0);
|
|
25
|
+
});
|
|
26
|
+
it("apoptosed=true when fitness drops below threshold", () => {
|
|
27
|
+
const g = createGenome();
|
|
28
|
+
applyEvolutionaryPressure(g, { id: "init", ts: 1, kind: "verified-good", strainId: "x", trace: "ok" });
|
|
29
|
+
// Crush it with many rejections
|
|
30
|
+
for (let i = 0; i < 20; i++) {
|
|
31
|
+
applyEvolutionaryPressure(g, { id: `r${i}`, ts: 10 + i, kind: "user-rejected", strainId: "x", trace: "no" });
|
|
32
|
+
}
|
|
33
|
+
expect(g.strains.get("x").apoptosed).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it("DNA fingerprint is deterministic + stable", () => {
|
|
36
|
+
const g1 = createGenome();
|
|
37
|
+
const events = [
|
|
38
|
+
{ id: "a", ts: 1, kind: "verified-good", strainId: "x", trace: "" },
|
|
39
|
+
{ id: "b", ts: 2, kind: "user-rejected", strainId: "y", trace: "" },
|
|
40
|
+
];
|
|
41
|
+
batchApply(g1, events);
|
|
42
|
+
const dna1 = computeDnaFingerprint(g1);
|
|
43
|
+
const g2 = createGenome();
|
|
44
|
+
batchApply(g2, events);
|
|
45
|
+
const dna2 = computeDnaFingerprint(g2);
|
|
46
|
+
expect(dna1).toBe(dna2);
|
|
47
|
+
});
|
|
48
|
+
it("DNA fingerprint differs when EVENT ORDER differs", () => {
|
|
49
|
+
const a = [
|
|
50
|
+
{ id: "a", ts: 1, kind: "verified-good", strainId: "x", trace: "" },
|
|
51
|
+
{ id: "b", ts: 2, kind: "hallucination", strainId: "y", trace: "" },
|
|
52
|
+
];
|
|
53
|
+
const b = [
|
|
54
|
+
{ id: "b", ts: 2, kind: "hallucination", strainId: "y", trace: "" },
|
|
55
|
+
{ id: "a", ts: 1, kind: "verified-good", strainId: "x", trace: "" },
|
|
56
|
+
];
|
|
57
|
+
const g1 = createGenome();
|
|
58
|
+
batchApply(g1, a);
|
|
59
|
+
const g2 = createGenome();
|
|
60
|
+
batchApply(g2, b);
|
|
61
|
+
expect(computeDnaFingerprint(g1)).not.toBe(computeDnaFingerprint(g2));
|
|
62
|
+
});
|
|
63
|
+
it("personalityReport produces sigma deviations against baseline", () => {
|
|
64
|
+
const g = createGenome();
|
|
65
|
+
applyEvolutionaryPressure(g, { id: "a", ts: 1, kind: "verified-good", strainId: "x", trace: "" });
|
|
66
|
+
applyEvolutionaryPressure(g, { id: "b", ts: 2, kind: "verified-good", strainId: "x", trace: "" });
|
|
67
|
+
applyEvolutionaryPressure(g, { id: "c", ts: 3, kind: "verified-good", strainId: "x", trace: "" });
|
|
68
|
+
const r = personalityReport(g, { meanFitness: { x: 1.0 }, stdDev: { x: 0.05 } });
|
|
69
|
+
expect(r.sigmaDeviations.length).toBeGreaterThan(0);
|
|
70
|
+
expect(r.sigmaDeviations[0].strainId).toBe("x");
|
|
71
|
+
expect(r.sigmaDeviations[0].sigma).toBeGreaterThan(2);
|
|
72
|
+
});
|
|
73
|
+
it("personalityReport summary mentions top deviation", () => {
|
|
74
|
+
const g = createGenome();
|
|
75
|
+
applyEvolutionaryPressure(g, { id: "a", ts: 1, kind: "verified-good", strainId: "x", trace: "" });
|
|
76
|
+
const r = personalityReport(g, { meanFitness: { x: 1.0 }, stdDev: { x: 0.05 } });
|
|
77
|
+
expect(r.summary).toContain("σ");
|
|
78
|
+
});
|
|
79
|
+
it("formatBloodlinePulseLine produces compact summary", () => {
|
|
80
|
+
const g = createGenome();
|
|
81
|
+
applyEvolutionaryPressure(g, { id: "a", ts: 1, kind: "verified-good", strainId: "x", trace: "" });
|
|
82
|
+
const line = formatBloodlinePulseLine(g);
|
|
83
|
+
expect(line).toContain("BLOODLINE");
|
|
84
|
+
expect(line).toContain("DNA=");
|
|
85
|
+
});
|
|
86
|
+
it("serialize → parse round-trip", () => {
|
|
87
|
+
const g = createGenome();
|
|
88
|
+
applyEvolutionaryPressure(g, { id: "a", ts: 1, kind: "verified-good", strainId: "x", trace: "" });
|
|
89
|
+
const text = serializeGenome(g);
|
|
90
|
+
const parsed = parseGenome(text);
|
|
91
|
+
expect(parsed).not.toBeNull();
|
|
92
|
+
expect(parsed.strains.get("x")?.fitness).toBeCloseTo(1.10, 5);
|
|
93
|
+
expect(parsed.history.length).toBe(1);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=bloodline.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bloodline.test.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"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2.0.0 -- BLOODLINE · Personal AI Genetic Strain
|
|
3
|
+
*
|
|
4
|
+
* "After 6 months, your Mneme is no longer the same species as anyone
|
|
5
|
+
* else's. They cloned the repo — they got the phenotype, not the
|
|
6
|
+
* genotype."
|
|
7
|
+
*
|
|
8
|
+
* Mneme already ships:
|
|
9
|
+
* - MneMeiosis chromosomes (genome of decisions / regrets / wisdoms)
|
|
10
|
+
* - ATOM karma per chromosome
|
|
11
|
+
* - apoptosis (cell death) on consistently-bad chromosomes
|
|
12
|
+
*
|
|
13
|
+
* What was MISSING: evolutionary pressure that selects, mutates, and
|
|
14
|
+
* propagates chromosomes over time. BLOODLINE adds it. Three loops:
|
|
15
|
+
*
|
|
16
|
+
* ✓ verified-good outcome → reinforce chromosome fitness +0.10
|
|
17
|
+
* ⚠ hallucination caught → propagate vaccine variant
|
|
18
|
+
* ✗ user rejected → decay branch fitness -0.20
|
|
19
|
+
*
|
|
20
|
+
* Plus a DNA fingerprint that's a deterministic hash of the user's
|
|
21
|
+
* cumulative fitness landscape — guaranteed unique across users after
|
|
22
|
+
* a few weeks of normal use because no two users land the same
|
|
23
|
+
* sequence of verified-good / hallucination / rejection events.
|
|
24
|
+
*
|
|
25
|
+
* Plus a "personality report" that grades this user's genome against a
|
|
26
|
+
* neutral baseline: "your AI is 3.7σ more cautious about Redis than
|
|
27
|
+
* baseline (incident 2026-03-14 still influences your chromosome
|
|
28
|
+
* `c0ff33-redis-sessions`)".
|
|
29
|
+
*
|
|
30
|
+
* Pure function. Deterministic. No external deps.
|
|
31
|
+
* Backward compatible — composes with chromosomes/vaccines that already exist.
|
|
32
|
+
*/
|
|
33
|
+
export type EventKind = "verified-good" | "hallucination" | "user-rejected" | "user-confirmed";
|
|
34
|
+
export interface BloodlineEvent {
|
|
35
|
+
/** Stable id (sha256 prefix). */
|
|
36
|
+
id: string;
|
|
37
|
+
/** Wall-clock when the event happened. */
|
|
38
|
+
ts: number;
|
|
39
|
+
kind: EventKind;
|
|
40
|
+
/** Which chromosome/strain the event refers to. */
|
|
41
|
+
strainId: string;
|
|
42
|
+
/** Free-form narrative for audit. */
|
|
43
|
+
trace: string;
|
|
44
|
+
/** Optional 0..1 magnitude (e.g. severity of hallucination). */
|
|
45
|
+
weight?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface StrainState {
|
|
48
|
+
id: string;
|
|
49
|
+
/** Fitness 0..∞. Default 1.0. Reinforce adds, decay multiplies. */
|
|
50
|
+
fitness: number;
|
|
51
|
+
/** Number of events this strain has accumulated. */
|
|
52
|
+
events: number;
|
|
53
|
+
/** Number of vaccine variants spawned from this strain. */
|
|
54
|
+
vaccineVariants: number;
|
|
55
|
+
/** Last-touched timestamp. */
|
|
56
|
+
lastTouched: number;
|
|
57
|
+
/** Cumulative reinforcement (positive events). */
|
|
58
|
+
reinforced: number;
|
|
59
|
+
/** Cumulative decay (negative events). */
|
|
60
|
+
decayed: number;
|
|
61
|
+
/** True if strain is below apoptosis threshold (effectively dead). */
|
|
62
|
+
apoptosed: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface Genome {
|
|
65
|
+
/** Map strainId → state. */
|
|
66
|
+
strains: Map<string, StrainState>;
|
|
67
|
+
/** All events ever applied, newest last. */
|
|
68
|
+
history: BloodlineEvent[];
|
|
69
|
+
}
|
|
70
|
+
export declare function createGenome(): Genome;
|
|
71
|
+
/** Constants tunable per deployment (also exposed for tests). */
|
|
72
|
+
export declare const PRESSURE: {
|
|
73
|
+
REINFORCE_BOOST: number;
|
|
74
|
+
DECAY_FACTOR: number;
|
|
75
|
+
HALLUCINATION_VARIANT: number;
|
|
76
|
+
APOPTOSIS_THRESHOLD: number;
|
|
77
|
+
};
|
|
78
|
+
/** Apply one event to the genome. Mutates the genome IN PLACE — pure
|
|
79
|
+
* in the functional sense that same (genome, event) → same final state. */
|
|
80
|
+
export declare function applyEvolutionaryPressure(genome: Genome, event: BloodlineEvent): StrainState;
|
|
81
|
+
/** Batch-apply many events. */
|
|
82
|
+
export declare function batchApply(genome: Genome, events: readonly BloodlineEvent[]): void;
|
|
83
|
+
/** Compute a deterministic 16-hex DNA fingerprint that's unique across
|
|
84
|
+
* users after a handful of events. Sensitive to both WHICH strains and
|
|
85
|
+
* WHAT ORDER events arrived in. */
|
|
86
|
+
export declare function computeDnaFingerprint(genome: Genome): string;
|
|
87
|
+
export interface BaselineStats {
|
|
88
|
+
/** Map strainId → expected mean fitness in the population. */
|
|
89
|
+
meanFitness: Record<string, number>;
|
|
90
|
+
/** Map strainId → population stddev. */
|
|
91
|
+
stdDev: Record<string, number>;
|
|
92
|
+
}
|
|
93
|
+
export interface PersonalityReport {
|
|
94
|
+
totalStrains: number;
|
|
95
|
+
apoptosedStrains: number;
|
|
96
|
+
topReinforced: Array<{
|
|
97
|
+
strainId: string;
|
|
98
|
+
fitness: number;
|
|
99
|
+
reinforced: number;
|
|
100
|
+
}>;
|
|
101
|
+
topDecayed: Array<{
|
|
102
|
+
strainId: string;
|
|
103
|
+
fitness: number;
|
|
104
|
+
decayed: number;
|
|
105
|
+
}>;
|
|
106
|
+
sigmaDeviations: Array<{
|
|
107
|
+
strainId: string;
|
|
108
|
+
fitness: number;
|
|
109
|
+
baseline: number;
|
|
110
|
+
sigma: number;
|
|
111
|
+
}>;
|
|
112
|
+
/** Cumulative reinforcement minus decay — overall colony health. */
|
|
113
|
+
healthScore: number;
|
|
114
|
+
/** Best-effort one-liner for AI agent to surface. */
|
|
115
|
+
summary: string;
|
|
116
|
+
}
|
|
117
|
+
/** Compute the personality report given the user's genome and an
|
|
118
|
+
* optional population baseline. */
|
|
119
|
+
export declare function personalityReport(genome: Genome, baseline?: BaselineStats): PersonalityReport;
|
|
120
|
+
export declare function formatBloodlinePulseLine(genome: Genome): string;
|
|
121
|
+
/** Serialize the genome to JSON for persistence in .mneme/bloodline.json. */
|
|
122
|
+
export declare function serializeGenome(genome: Genome): string;
|
|
123
|
+
export declare function parseGenome(text: string): Genome | null;
|
|
124
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bloodline/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAIH,MAAM,MAAM,SAAS,GAAG,eAAe,GAAG,eAAe,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAE/F,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,0CAA0C;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,SAAS,CAAC;IAChB,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,eAAe,EAAE,MAAM,CAAC;IACxB,8BAA8B;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,MAAM;IACrB,4BAA4B;IAC5B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAClC,4CAA4C;IAC5C,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAMD,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,iEAAiE;AACjE,eAAO,MAAM,QAAQ;;;;;CAKpB,CAAC;AAEF;4EAC4E;AAC5E,wBAAg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,MAAM,EAAE,MAAM,GAAG,MAAM,CAI/D;AAED,6EAA6E;AAC7E,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMtD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUvD"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2.0.0 -- BLOODLINE · Personal AI Genetic Strain
|
|
3
|
+
*
|
|
4
|
+
* "After 6 months, your Mneme is no longer the same species as anyone
|
|
5
|
+
* else's. They cloned the repo — they got the phenotype, not the
|
|
6
|
+
* genotype."
|
|
7
|
+
*
|
|
8
|
+
* Mneme already ships:
|
|
9
|
+
* - MneMeiosis chromosomes (genome of decisions / regrets / wisdoms)
|
|
10
|
+
* - ATOM karma per chromosome
|
|
11
|
+
* - apoptosis (cell death) on consistently-bad chromosomes
|
|
12
|
+
*
|
|
13
|
+
* What was MISSING: evolutionary pressure that selects, mutates, and
|
|
14
|
+
* propagates chromosomes over time. BLOODLINE adds it. Three loops:
|
|
15
|
+
*
|
|
16
|
+
* ✓ verified-good outcome → reinforce chromosome fitness +0.10
|
|
17
|
+
* ⚠ hallucination caught → propagate vaccine variant
|
|
18
|
+
* ✗ user rejected → decay branch fitness -0.20
|
|
19
|
+
*
|
|
20
|
+
* Plus a DNA fingerprint that's a deterministic hash of the user's
|
|
21
|
+
* cumulative fitness landscape — guaranteed unique across users after
|
|
22
|
+
* a few weeks of normal use because no two users land the same
|
|
23
|
+
* sequence of verified-good / hallucination / rejection events.
|
|
24
|
+
*
|
|
25
|
+
* Plus a "personality report" that grades this user's genome against a
|
|
26
|
+
* neutral baseline: "your AI is 3.7σ more cautious about Redis than
|
|
27
|
+
* baseline (incident 2026-03-14 still influences your chromosome
|
|
28
|
+
* `c0ff33-redis-sessions`)".
|
|
29
|
+
*
|
|
30
|
+
* Pure function. Deterministic. No external deps.
|
|
31
|
+
* Backward compatible — composes with chromosomes/vaccines that already exist.
|
|
32
|
+
*/
|
|
33
|
+
import { createHash } from "node:crypto";
|
|
34
|
+
// ============================================================
|
|
35
|
+
// Genome lifecycle
|
|
36
|
+
// ============================================================
|
|
37
|
+
export function createGenome() {
|
|
38
|
+
return { strains: new Map(), history: [] };
|
|
39
|
+
}
|
|
40
|
+
/** Constants tunable per deployment (also exposed for tests). */
|
|
41
|
+
export const PRESSURE = {
|
|
42
|
+
REINFORCE_BOOST: 0.10,
|
|
43
|
+
DECAY_FACTOR: 0.80, // multiply fitness by this on user-rejected
|
|
44
|
+
HALLUCINATION_VARIANT: 0.05, // small fitness bump for the parent strain when a vaccine variant is spawned
|
|
45
|
+
APOPTOSIS_THRESHOLD: 0.10, // below this fitness → strain marked apoptosed
|
|
46
|
+
};
|
|
47
|
+
/** Apply one event to the genome. Mutates the genome IN PLACE — pure
|
|
48
|
+
* in the functional sense that same (genome, event) → same final state. */
|
|
49
|
+
export function applyEvolutionaryPressure(genome, event) {
|
|
50
|
+
let strain = genome.strains.get(event.strainId);
|
|
51
|
+
if (!strain) {
|
|
52
|
+
strain = {
|
|
53
|
+
id: event.strainId,
|
|
54
|
+
fitness: 1.0,
|
|
55
|
+
events: 0,
|
|
56
|
+
vaccineVariants: 0,
|
|
57
|
+
lastTouched: event.ts,
|
|
58
|
+
reinforced: 0,
|
|
59
|
+
decayed: 0,
|
|
60
|
+
apoptosed: false,
|
|
61
|
+
};
|
|
62
|
+
genome.strains.set(event.strainId, strain);
|
|
63
|
+
}
|
|
64
|
+
const weight = event.weight ?? 1.0;
|
|
65
|
+
switch (event.kind) {
|
|
66
|
+
case "verified-good":
|
|
67
|
+
case "user-confirmed": {
|
|
68
|
+
const boost = PRESSURE.REINFORCE_BOOST * weight;
|
|
69
|
+
strain.fitness += boost;
|
|
70
|
+
strain.reinforced += boost;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case "hallucination": {
|
|
74
|
+
// Spawn a vaccine variant for this strain. Slight reinforcement for
|
|
75
|
+
// the parent strain because catching a hallucination IS a fitness signal.
|
|
76
|
+
strain.vaccineVariants += 1;
|
|
77
|
+
const bump = PRESSURE.HALLUCINATION_VARIANT * weight;
|
|
78
|
+
strain.fitness += bump;
|
|
79
|
+
strain.reinforced += bump;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case "user-rejected": {
|
|
83
|
+
const factor = Math.pow(PRESSURE.DECAY_FACTOR, weight);
|
|
84
|
+
const beforeFit = strain.fitness;
|
|
85
|
+
strain.fitness *= factor;
|
|
86
|
+
strain.decayed += (beforeFit - strain.fitness);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
strain.events += 1;
|
|
91
|
+
strain.lastTouched = event.ts;
|
|
92
|
+
strain.apoptosed = strain.fitness < PRESSURE.APOPTOSIS_THRESHOLD;
|
|
93
|
+
genome.history.push(event);
|
|
94
|
+
return strain;
|
|
95
|
+
}
|
|
96
|
+
/** Batch-apply many events. */
|
|
97
|
+
export function batchApply(genome, events) {
|
|
98
|
+
for (const e of events)
|
|
99
|
+
applyEvolutionaryPressure(genome, e);
|
|
100
|
+
}
|
|
101
|
+
// ============================================================
|
|
102
|
+
// DNA Fingerprint
|
|
103
|
+
// ============================================================
|
|
104
|
+
/** Compute a deterministic 16-hex DNA fingerprint that's unique across
|
|
105
|
+
* users after a handful of events. Sensitive to both WHICH strains and
|
|
106
|
+
* WHAT ORDER events arrived in. */
|
|
107
|
+
export function computeDnaFingerprint(genome) {
|
|
108
|
+
const h = createHash("sha256");
|
|
109
|
+
// Sort strains by id for stable hashing.
|
|
110
|
+
const sorted = [...genome.strains.values()].sort((a, b) => a.id.localeCompare(b.id));
|
|
111
|
+
for (const s of sorted) {
|
|
112
|
+
h.update(`${s.id}|${s.fitness.toFixed(6)}|${s.events}|${s.vaccineVariants}|${s.apoptosed ? "X" : "."};`);
|
|
113
|
+
}
|
|
114
|
+
// Also include event arrival ORDER (a unique-to-user signal).
|
|
115
|
+
for (const e of genome.history) {
|
|
116
|
+
h.update(`${e.kind}|${e.strainId};`);
|
|
117
|
+
}
|
|
118
|
+
return h.digest("hex").slice(0, 16);
|
|
119
|
+
}
|
|
120
|
+
/** Compute the personality report given the user's genome and an
|
|
121
|
+
* optional population baseline. */
|
|
122
|
+
export function personalityReport(genome, baseline) {
|
|
123
|
+
const all = [...genome.strains.values()];
|
|
124
|
+
const apoptosed = all.filter((s) => s.apoptosed).length;
|
|
125
|
+
const topReinforced = [...all].sort((a, b) => b.reinforced - a.reinforced).slice(0, 5).map((s) => ({ strainId: s.id, fitness: s.fitness, reinforced: s.reinforced }));
|
|
126
|
+
const topDecayed = [...all].sort((a, b) => b.decayed - a.decayed).slice(0, 5).map((s) => ({ strainId: s.id, fitness: s.fitness, decayed: s.decayed }));
|
|
127
|
+
const sigmaDeviations = [];
|
|
128
|
+
if (baseline) {
|
|
129
|
+
for (const s of all) {
|
|
130
|
+
const mean = baseline.meanFitness[s.id];
|
|
131
|
+
const sd = baseline.stdDev[s.id];
|
|
132
|
+
if (mean === undefined || sd === undefined || sd === 0)
|
|
133
|
+
continue;
|
|
134
|
+
const sigma = (s.fitness - mean) / sd;
|
|
135
|
+
if (Math.abs(sigma) >= 1)
|
|
136
|
+
sigmaDeviations.push({ strainId: s.id, fitness: s.fitness, baseline: mean, sigma });
|
|
137
|
+
}
|
|
138
|
+
sigmaDeviations.sort((a, b) => Math.abs(b.sigma) - Math.abs(a.sigma));
|
|
139
|
+
}
|
|
140
|
+
const healthScore = all.reduce((sum, s) => sum + s.reinforced - s.decayed, 0);
|
|
141
|
+
let summary = `BLOODLINE · ${all.length} strain(s) · ${apoptosed} apoptosed · health=${healthScore.toFixed(2)}`;
|
|
142
|
+
if (sigmaDeviations.length > 0) {
|
|
143
|
+
const top = sigmaDeviations[0];
|
|
144
|
+
const direction = top.sigma > 0 ? "more aggressive at reinforcing" : "more cautious about";
|
|
145
|
+
summary += ` · top deviation: ${top.sigma.toFixed(1)}σ ${direction} '${top.strainId}'`;
|
|
146
|
+
}
|
|
147
|
+
return { totalStrains: all.length, apoptosedStrains: apoptosed, topReinforced, topDecayed, sigmaDeviations, healthScore, summary };
|
|
148
|
+
}
|
|
149
|
+
// ============================================================
|
|
150
|
+
// Pulse line + serialization
|
|
151
|
+
// ============================================================
|
|
152
|
+
export function formatBloodlinePulseLine(genome) {
|
|
153
|
+
const dna = computeDnaFingerprint(genome);
|
|
154
|
+
const r = personalityReport(genome);
|
|
155
|
+
return `BLOODLINE · DNA=${dna} · ${r.totalStrains} strain(s) · ${r.apoptosedStrains} apoptosed · health=${r.healthScore.toFixed(2)}`;
|
|
156
|
+
}
|
|
157
|
+
/** Serialize the genome to JSON for persistence in .mneme/bloodline.json. */
|
|
158
|
+
export function serializeGenome(genome) {
|
|
159
|
+
// StrainState already has an `id` field; just dump the values.
|
|
160
|
+
return JSON.stringify({
|
|
161
|
+
strains: [...genome.strains.values()],
|
|
162
|
+
history: genome.history,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
export function parseGenome(text) {
|
|
166
|
+
try {
|
|
167
|
+
const obj = JSON.parse(text);
|
|
168
|
+
if (!obj || !Array.isArray(obj.strains) || !Array.isArray(obj.history))
|
|
169
|
+
return null;
|
|
170
|
+
const strains = new Map();
|
|
171
|
+
for (const s of obj.strains)
|
|
172
|
+
strains.set(s.id, s);
|
|
173
|
+
return { strains, history: obj.history };
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bloodline/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA2CzC,+DAA+D;AAC/D,mBAAmB;AACnB,+DAA+D;AAE/D,MAAM,UAAU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