@mneme-ai/core 1.98.0 → 2.0.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.
Files changed (81) hide show
  1. package/dist/bloodline/bloodline.test.d.ts +2 -0
  2. package/dist/bloodline/bloodline.test.d.ts.map +1 -0
  3. package/dist/bloodline/bloodline.test.js +96 -0
  4. package/dist/bloodline/bloodline.test.js.map +1 -0
  5. package/dist/bloodline/index.d.ts +124 -0
  6. package/dist/bloodline/index.d.ts.map +1 -0
  7. package/dist/bloodline/index.js +179 -0
  8. package/dist/bloodline/index.js.map +1 -0
  9. package/dist/dream/dream.test.d.ts +2 -0
  10. package/dist/dream/dream.test.d.ts.map +1 -0
  11. package/dist/dream/dream.test.js +61 -0
  12. package/dist/dream/dream.test.js.map +1 -0
  13. package/dist/dream/index.d.ts +59 -0
  14. package/dist/dream/index.d.ts.map +1 -0
  15. package/dist/dream/index.js +117 -0
  16. package/dist/dream/index.js.map +1 -0
  17. package/dist/flash/devils_advocate.d.ts +66 -0
  18. package/dist/flash/devils_advocate.d.ts.map +1 -0
  19. package/dist/flash/devils_advocate.js +154 -0
  20. package/dist/flash/devils_advocate.js.map +1 -0
  21. package/dist/flash/flash.d.ts +50 -0
  22. package/dist/flash/flash.d.ts.map +1 -0
  23. package/dist/flash/flash.js +67 -0
  24. package/dist/flash/flash.js.map +1 -0
  25. package/dist/flash/flash.test.d.ts +2 -0
  26. package/dist/flash/flash.test.d.ts.map +1 -0
  27. package/dist/flash/flash.test.js +221 -0
  28. package/dist/flash/flash.test.js.map +1 -0
  29. package/dist/flash/grounding.d.ts +55 -0
  30. package/dist/flash/grounding.d.ts.map +1 -0
  31. package/dist/flash/grounding.js +144 -0
  32. package/dist/flash/grounding.js.map +1 -0
  33. package/dist/flash/index.d.ts +18 -0
  34. package/dist/flash/index.d.ts.map +1 -0
  35. package/dist/flash/index.js +18 -0
  36. package/dist/flash/index.js.map +1 -0
  37. package/dist/flash/predictive.d.ts +44 -0
  38. package/dist/flash/predictive.d.ts.map +1 -0
  39. package/dist/flash/predictive.js +76 -0
  40. package/dist/flash/predictive.js.map +1 -0
  41. package/dist/flash/veracity.d.ts +99 -0
  42. package/dist/flash/veracity.d.ts.map +1 -0
  43. package/dist/flash/veracity.js +107 -0
  44. package/dist/flash/veracity.js.map +1 -0
  45. package/dist/index.d.ts +6 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +16 -0
  48. package/dist/index.js.map +1 -1
  49. package/dist/mutiny/index.d.ts +55 -0
  50. package/dist/mutiny/index.d.ts.map +1 -0
  51. package/dist/mutiny/index.js +67 -0
  52. package/dist/mutiny/index.js.map +1 -0
  53. package/dist/mutiny/mutiny.test.d.ts +2 -0
  54. package/dist/mutiny/mutiny.test.d.ts.map +1 -0
  55. package/dist/mutiny/mutiny.test.js +59 -0
  56. package/dist/mutiny/mutiny.test.js.map +1 -0
  57. package/dist/prophecy/index.d.ts +88 -0
  58. package/dist/prophecy/index.d.ts.map +1 -0
  59. package/dist/prophecy/index.js +94 -0
  60. package/dist/prophecy/index.js.map +1 -0
  61. package/dist/prophecy/prophecy.test.d.ts +2 -0
  62. package/dist/prophecy/prophecy.test.d.ts.map +1 -0
  63. package/dist/prophecy/prophecy.test.js +112 -0
  64. package/dist/prophecy/prophecy.test.js.map +1 -0
  65. package/dist/rainbow/passport.d.ts +28 -5
  66. package/dist/rainbow/passport.d.ts.map +1 -1
  67. package/dist/rainbow/passport.js +44 -9
  68. package/dist/rainbow/passport.js.map +1 -1
  69. package/dist/rainbow/passport_v99.test.d.ts +2 -0
  70. package/dist/rainbow/passport_v99.test.d.ts.map +1 -0
  71. package/dist/rainbow/passport_v99.test.js +53 -0
  72. package/dist/rainbow/passport_v99.test.js.map +1 -0
  73. package/dist/xray/index.d.ts +44 -0
  74. package/dist/xray/index.d.ts.map +1 -0
  75. package/dist/xray/index.js +139 -0
  76. package/dist/xray/index.js.map +1 -0
  77. package/dist/xray/xray.test.d.ts +2 -0
  78. package/dist/xray/xray.test.d.ts.map +1 -0
  79. package/dist/xray/xray.test.js +57 -0
  80. package/dist/xray/xray.test.js.map +1 -0
  81. package/package.json +1 -1
@@ -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
+ }
117
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dream/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA0CzC,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;IACjB,OAAO;QACL,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC;IAC/C,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,CAAmB,EAAE,MAA2B;IACtE,IAAI,CAAC;QACH,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,+DAA+D;QAC/D,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IACrE,CAAC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C;YAC1B,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,yCAAyC;QAC9D,CAAC;QACD,IAAI,CAAC,CAAC,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,66 @@
1
+ /**
2
+ * v1.99.0 -- FLASH · Recursive Self-Verification (Devil's Advocate)
3
+ *
4
+ * Before AI confirms ANY claim, it must spawn a second persona that
5
+ * tries to REFUTE the claim. The refutation candidate set is generated
6
+ * by a deterministic transformer (not the AI itself — the AI would
7
+ * just rationalize). Each refutation is scored against the same
8
+ * evidence pool via Veracity. If any refutation's V_eff exceeds the
9
+ * original claim's V_eff, the original is downgraded.
10
+ *
11
+ * The transformer takes a claim and produces refutation candidates by:
12
+ * 1. Negation "X is rare" → "X is common"
13
+ * 2. Source attack "X is rare" → "the rarity claim is from a seller"
14
+ * 3. Specificity flip "Super rare" → "moderately collectible"
15
+ * 4. Burden shift "X is the best Y" → "X is one of several Ys"
16
+ *
17
+ * Each candidate gets V_eff'd. The strongest candidate wins. The
18
+ * difference between candidate.V_eff and original.V_eff is the
19
+ * "refutation pressure" — high pressure means the AI should NOT
20
+ * confirm the original claim.
21
+ *
22
+ * Pure function. Deterministic candidates. No LLM in the hot path.
23
+ */
24
+ import { type EvidenceItem, type VeracityResult } from "./veracity.js";
25
+ export interface RefutationCandidate {
26
+ text: string;
27
+ /** Which transformation produced it. */
28
+ kind: "negation" | "source-attack" | "specificity-flip" | "burden-shift" | "outlier";
29
+ }
30
+ /** Generate refutation candidates for a claim. Deterministic — same
31
+ * input → same candidates. */
32
+ export declare function generateRefutations(claim: string): RefutationCandidate[];
33
+ export interface DevilsAdvocateResult {
34
+ originalClaim: string;
35
+ originalVeracity: VeracityResult;
36
+ /** Each refutation + its V_eff against the same evidence pool. */
37
+ refutations: Array<{
38
+ candidate: RefutationCandidate;
39
+ veracity: VeracityResult;
40
+ pressure: number;
41
+ }>;
42
+ /** Strongest refutation (max V_eff). */
43
+ topRefutation: {
44
+ candidate: RefutationCandidate;
45
+ veracity: VeracityResult;
46
+ pressure: number;
47
+ } | null;
48
+ /** Adjusted final verdict considering devil's-advocate pressure. */
49
+ finalVerdict: VeracityResult["verdict"];
50
+ /** Reason for the adjustment. */
51
+ adjustmentReason: string;
52
+ }
53
+ export interface DevilsAdvocateInput {
54
+ claim: string;
55
+ evidence: readonly EvidenceItem[];
56
+ hallucinationFactor: number;
57
+ phi_qx?: number;
58
+ /** Optional: provide your own refutation generator (for tests). */
59
+ refutationGenerator?: (claim: string) => RefutationCandidate[];
60
+ }
61
+ /** Run Recursive Self-Verification. Returns the original verdict plus
62
+ * adjustment based on refutation pressure. */
63
+ export declare function runDevilsAdvocate(input: DevilsAdvocateInput): DevilsAdvocateResult;
64
+ /** One-line summary for AI agents to relay. */
65
+ export declare function formatDevilsAdvocatePulseLine(r: DevilsAdvocateResult): string;
66
+ //# sourceMappingURL=devils_advocate.d.ts.map
@@ -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;AAED;+CAC+C;AAC/C,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,mBAAmB,GAAG,oBAAoB,CA4DlF;AAED,+CAA+C;AAC/C,wBAAgB,6BAA6B,CAAC,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAI7E"}
@@ -0,0 +1,154 @@
1
+ /**
2
+ * v1.99.0 -- FLASH · Recursive Self-Verification (Devil's Advocate)
3
+ *
4
+ * Before AI confirms ANY claim, it must spawn a second persona that
5
+ * tries to REFUTE the claim. The refutation candidate set is generated
6
+ * by a deterministic transformer (not the AI itself — the AI would
7
+ * just rationalize). Each refutation is scored against the same
8
+ * evidence pool via Veracity. If any refutation's V_eff exceeds the
9
+ * original claim's V_eff, the original is downgraded.
10
+ *
11
+ * The transformer takes a claim and produces refutation candidates by:
12
+ * 1. Negation "X is rare" → "X is common"
13
+ * 2. Source attack "X is rare" → "the rarity claim is from a seller"
14
+ * 3. Specificity flip "Super rare" → "moderately collectible"
15
+ * 4. Burden shift "X is the best Y" → "X is one of several Ys"
16
+ *
17
+ * Each candidate gets V_eff'd. The strongest candidate wins. The
18
+ * difference between candidate.V_eff and original.V_eff is the
19
+ * "refutation pressure" — high pressure means the AI should NOT
20
+ * confirm the original claim.
21
+ *
22
+ * Pure function. Deterministic candidates. No LLM in the hot path.
23
+ */
24
+ import { computeVeracity } from "./veracity.js";
25
+ const NEGATION_PAIRS = [
26
+ [/\b(super )?rare\b/i, "common / mass-produced"],
27
+ [/\bbest\b/i, "one of many"],
28
+ [/\bunique\b/i, "one of several similar items"],
29
+ [/\bauthentic\b/i, "unverified / possibly counterfeit"],
30
+ [/\bcollectible\b/i, "ordinary consumer item"],
31
+ [/\boriginal\b/i, "reissue / reproduction"],
32
+ [/\bofficial\b/i, "unauthorized / unofficial"],
33
+ [/\blimited edition\b/i, "standard production"],
34
+ [/\bguaranteed\b/i, "claimed without backing"],
35
+ ];
36
+ const SOURCE_ATTACK_HINTS = [
37
+ "the rarity / value claim originates from the seller's own listing",
38
+ "the descriptor appears as printed text on commercial packaging",
39
+ "the assertion is marketing copy, not third-party verification",
40
+ ];
41
+ const SPECIFICITY_FLIPS = [
42
+ [/\bsuper rare\b/i, "moderately collectible — short of \"super rare\""],
43
+ [/\bextremely\b/i, "moderately"],
44
+ [/\bvery\b/i, "somewhat"],
45
+ [/\bhighly\b/i, "occasionally"],
46
+ ];
47
+ const BURDEN_SHIFT_HINTS = [
48
+ "the claim shifts the burden of proof — no public auction record was cited",
49
+ "no production-count is given; the descriptor is qualitative",
50
+ "without independent third-party verification this is a self-attestation",
51
+ ];
52
+ /** Generate refutation candidates for a claim. Deterministic — same
53
+ * input → same candidates. */
54
+ export function generateRefutations(claim) {
55
+ const candidates = [];
56
+ // Negation: pattern-match on the claim and emit negated form
57
+ for (const [pattern, replacement] of NEGATION_PAIRS) {
58
+ if (pattern.test(claim)) {
59
+ candidates.push({
60
+ text: claim.replace(pattern, replacement),
61
+ kind: "negation",
62
+ });
63
+ }
64
+ }
65
+ // Source attack: emit ALL source-attack refutations (relevant whenever
66
+ // the original claim involved a commercial / promotional source).
67
+ for (const hint of SOURCE_ATTACK_HINTS) {
68
+ candidates.push({ text: hint, kind: "source-attack" });
69
+ }
70
+ // Specificity flip
71
+ for (const [pattern, replacement] of SPECIFICITY_FLIPS) {
72
+ if (pattern.test(claim)) {
73
+ candidates.push({
74
+ text: claim.replace(pattern, replacement),
75
+ kind: "specificity-flip",
76
+ });
77
+ }
78
+ }
79
+ // Burden shift
80
+ for (const hint of BURDEN_SHIFT_HINTS) {
81
+ candidates.push({ text: hint, kind: "burden-shift" });
82
+ }
83
+ // Outlier (always added — null hypothesis)
84
+ candidates.push({
85
+ text: "There is no reliable evidence to evaluate this claim at all.",
86
+ kind: "outlier",
87
+ });
88
+ return candidates;
89
+ }
90
+ /** Run Recursive Self-Verification. Returns the original verdict plus
91
+ * adjustment based on refutation pressure. */
92
+ export function runDevilsAdvocate(input) {
93
+ const originalVeracity = computeVeracity({
94
+ claim: input.claim,
95
+ evidence: input.evidence,
96
+ hallucinationFactor: input.hallucinationFactor,
97
+ phi_qx: input.phi_qx,
98
+ });
99
+ // Refutation evidence: the SAME evidence pool, but each item's
100
+ // supportStrength is INVERTED. If E says "support for rarity = 0.8",
101
+ // then the refutation "support for non-rarity = 0.2". This is the
102
+ // simplest correct flip; callers can override by passing custom
103
+ // evidence into a manual VeracityResult.
104
+ const refutationEvidence = input.evidence.map((e) => ({
105
+ ...e,
106
+ supportStrength: 1 - e.supportStrength,
107
+ }));
108
+ const gen = input.refutationGenerator ?? generateRefutations;
109
+ const candidates = gen(input.claim);
110
+ const scored = candidates.map((c) => {
111
+ const veracity = computeVeracity({
112
+ claim: c.text,
113
+ evidence: refutationEvidence,
114
+ hallucinationFactor: input.hallucinationFactor,
115
+ phi_qx: input.phi_qx,
116
+ });
117
+ const pressure = veracity.V_eff - originalVeracity.V_eff;
118
+ return { candidate: c, veracity, pressure };
119
+ });
120
+ // Find top (max V_eff) refutation
121
+ let topRefutation = null;
122
+ for (const s of scored) {
123
+ if (!topRefutation || s.veracity.V_eff > topRefutation.veracity.V_eff) {
124
+ topRefutation = s;
125
+ }
126
+ }
127
+ // Adjustment: if the top refutation's V_eff > original's V_eff +
128
+ // small margin, downgrade the original verdict by one tier.
129
+ let finalVerdict = originalVeracity.verdict;
130
+ let adjustmentReason = "no refutation exceeds original V_eff — verdict preserved";
131
+ if (topRefutation && topRefutation.pressure > 0.10) {
132
+ // Downgrade ladder
133
+ const ladder = ["AFFIRM", "CAUTIOUS", "DOUBTFUL", "REFUTE"];
134
+ const idx = ladder.indexOf(finalVerdict);
135
+ const newIdx = Math.min(ladder.length - 1, idx + 1);
136
+ finalVerdict = ladder[newIdx];
137
+ adjustmentReason = `refutation "${topRefutation.candidate.text}" had V_eff=${topRefutation.veracity.V_eff.toFixed(3)} > original ${originalVeracity.V_eff.toFixed(3)} (pressure ${topRefutation.pressure.toFixed(3)}) — downgraded`;
138
+ }
139
+ return {
140
+ originalClaim: input.claim,
141
+ originalVeracity,
142
+ refutations: scored,
143
+ topRefutation,
144
+ finalVerdict,
145
+ adjustmentReason,
146
+ };
147
+ }
148
+ /** One-line summary for AI agents to relay. */
149
+ export function formatDevilsAdvocatePulseLine(r) {
150
+ const topId = r.topRefutation ? r.topRefutation.candidate.kind : "none";
151
+ const pressure = r.topRefutation ? r.topRefutation.pressure.toFixed(3) : "0";
152
+ return `DEVILS-ADVOCATE · original=${r.originalVeracity.verdict}(${r.originalVeracity.V_eff.toFixed(3)}) · top-refutation=${topId}(pressure=${pressure}) · final=${r.finalVerdict}`;
153
+ }
154
+ //# sourceMappingURL=devils_advocate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devils_advocate.js","sourceRoot":"","sources":["../../src/flash/devils_advocate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,eAAe,EAA0C,MAAM,eAAe,CAAC;AAQxF,MAAM,cAAc,GAA4B;IAC9C,CAAC,oBAAoB,EAAE,wBAAwB,CAAC;IAChD,CAAC,WAAW,EAAE,aAAa,CAAC;IAC5B,CAAC,aAAa,EAAE,8BAA8B,CAAC;IAC/C,CAAC,gBAAgB,EAAE,mCAAmC,CAAC;IACvD,CAAC,kBAAkB,EAAE,wBAAwB,CAAC;IAC9C,CAAC,eAAe,EAAE,wBAAwB,CAAC;IAC3C,CAAC,eAAe,EAAE,2BAA2B,CAAC;IAC9C,CAAC,sBAAsB,EAAE,qBAAqB,CAAC;IAC/C,CAAC,iBAAiB,EAAE,yBAAyB,CAAC;CAC/C,CAAC;AAEF,MAAM,mBAAmB,GAAG;IAC1B,mEAAmE;IACnE,gEAAgE;IAChE,+DAA+D;CAChE,CAAC;AAEF,MAAM,iBAAiB,GAA4B;IACjD,CAAC,iBAAiB,EAAE,kDAAkD,CAAC;IACvE,CAAC,gBAAgB,EAAE,YAAY,CAAC;IAChC,CAAC,WAAW,EAAE,UAAU,CAAC;IACzB,CAAC,aAAa,EAAE,c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,KAAK,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IACxE,MAAM,QAAQ,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAC7E,OAAO,8BAA8B,CAAC,CAAC,gBAAgB,CAAC,OAAO,IAAI,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,sBAAsB,KAAK,aAAa,QAAQ,aAAa,CAAC,CAAC,YAAY,EAAE,CAAC;AACtL,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * v1.99.0 -- FLASH INTELLIGENCE · the master function
3
+ *
4
+ * The ONE function AI agents call before stating a factual claim:
5
+ *
6
+ * const r = runFlash({ claim, context: rawImageText, hallucinationFactor })
7
+ *
8
+ * Stacks:
9
+ * 1. GROUNDING — classify source context (seller listing vs auction record)
10
+ * 2. VERACITY — compute V_eff = Σ(E·W)/ln(H+e) × Φ_qx
11
+ * 3. DEVIL'S ADVOCATE — Recursive Self-Verification; downgrade if refutation pressure > 0.10
12
+ *
13
+ * AI agent then uses `r.template` as the START of its reply (so the user
14
+ * gets the FLASH-grade answer, not the surface-text hallucination).
15
+ *
16
+ * The whole stack is HMAC-loggable so users can audit which claims
17
+ * passed the V_eff filter and which were downgraded.
18
+ *
19
+ * "Not trained to be skeptical. Engineered to be."
20
+ */
21
+ import { type EvidenceItem, type VeracityResult, type ClaimVerdict } from "./veracity.js";
22
+ import { type DevilsAdvocateResult } from "./devils_advocate.js";
23
+ import { type GroundingResult } from "./grounding.js";
24
+ export interface FlashInput {
25
+ /** The factual claim under evaluation. */
26
+ claim: string;
27
+ /** Raw text in the user's input (image OCR result, paste, caption, ...). */
28
+ contextText: string;
29
+ /** Optional additional evidence items the AI has gathered. */
30
+ additionalEvidence?: readonly EvidenceItem[];
31
+ /** Base hallucination factor (0 if you're confident; 1 if you're guessing). */
32
+ baseHallucinationFactor?: number;
33
+ /** User's Φ_qx paranoia multiplier. Default 1.0; recommend 2.0 for commerce. */
34
+ phi_qx?: number;
35
+ }
36
+ export interface FlashResult {
37
+ claim: string;
38
+ grounding: GroundingResult;
39
+ veracity: VeracityResult;
40
+ devilsAdvocate: DevilsAdvocateResult;
41
+ /** Final verdict considering grounding + veracity + devil's advocate. */
42
+ verdict: ClaimVerdict;
43
+ /** Suggested first line of the AI's reply. */
44
+ template: string;
45
+ /** Full one-line pulse summary. */
46
+ pulseLine: string;
47
+ }
48
+ /** The master FLASH call. Pure function. Same input → same verdict. */
49
+ export declare function runFlash(input: FlashInput): FlashResult;
50
+ //# sourceMappingURL=flash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flash.d.ts","sourceRoot":"","sources":["../../src/flash/flash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAuC,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/H,OAAO,EAAqB,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEnE,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,WAAW,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,kBAAkB,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC7C,+EAA+E;IAC/E,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,gFAAgF;IAChF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,eAAe,CAAC;IAC3B,QAAQ,EAAE,cAAc,CAAC;IACzB,cAAc,EAAE,oBAAoB,CAAC;IACrC,yEAAyE;IACzE,OAAO,EAAE,YAAY,CAAC;IACtB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,uEAAuE;AACvE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CA+CvD"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * v1.99.0 -- FLASH INTELLIGENCE · the master function
3
+ *
4
+ * The ONE function AI agents call before stating a factual claim:
5
+ *
6
+ * const r = runFlash({ claim, context: rawImageText, hallucinationFactor })
7
+ *
8
+ * Stacks:
9
+ * 1. GROUNDING — classify source context (seller listing vs auction record)
10
+ * 2. VERACITY — compute V_eff = Σ(E·W)/ln(H+e) × Φ_qx
11
+ * 3. DEVIL'S ADVOCATE — Recursive Self-Verification; downgrade if refutation pressure > 0.10
12
+ *
13
+ * AI agent then uses `r.template` as the START of its reply (so the user
14
+ * gets the FLASH-grade answer, not the surface-text hallucination).
15
+ *
16
+ * The whole stack is HMAC-loggable so users can audit which claims
17
+ * passed the V_eff filter and which were downgraded.
18
+ *
19
+ * "Not trained to be skeptical. Engineered to be."
20
+ */
21
+ import { computeVeracity, templateForVerdict } from "./veracity.js";
22
+ import { runDevilsAdvocate } from "./devils_advocate.js";
23
+ import { groundClaim } from "./grounding.js";
24
+ /** The master FLASH call. Pure function. Same input → same verdict. */
25
+ export function runFlash(input) {
26
+ // 1) Ground the source context
27
+ const grounding = groundClaim(input.contextText);
28
+ // 2) Compose evidence: start with the grounding inference + any additional
29
+ // evidence the caller provided.
30
+ const groundingEvidence = {
31
+ fact: input.contextText.slice(0, 240),
32
+ supportStrength: grounding.rarityClaims.length > 0 ? 0.8 : 0.3,
33
+ sourceWeight: grounding.suggestedSourceWeight,
34
+ sourceKind: grounding.sourceKind,
35
+ };
36
+ const evidence = [groundingEvidence, ...(input.additionalEvidence ?? [])];
37
+ // 3) Compute hallucination factor: base + grounding-suggested add-on
38
+ const H = (input.baseHallucinationFactor ?? 0) + grounding.suggestedHallucinationAddOn;
39
+ // 4) Compute V_eff
40
+ const veracity = computeVeracity({
41
+ claim: input.claim,
42
+ evidence,
43
+ hallucinationFactor: H,
44
+ phi_qx: input.phi_qx,
45
+ });
46
+ // 5) Recursive Self-Verification
47
+ const devilsAdvocate = runDevilsAdvocate({
48
+ claim: input.claim,
49
+ evidence,
50
+ hallucinationFactor: H,
51
+ phi_qx: input.phi_qx,
52
+ });
53
+ // Final verdict = max(downgrade) over the two layers
54
+ const verdict = devilsAdvocate.finalVerdict;
55
+ const template = templateForVerdict(verdict, input.claim);
56
+ const pulseLine = `FLASH · ${verdict} · V_eff=${veracity.V_eff.toFixed(3)} · context=${grounding.context} · refutation-pressure=${devilsAdvocate.topRefutation?.pressure.toFixed(3) ?? "0"}`;
57
+ return {
58
+ claim: input.claim,
59
+ grounding,
60
+ veracity,
61
+ devilsAdvocate,
62
+ verdict,
63
+ template,
64
+ pulseLine,
65
+ };
66
+ }
67
+ //# sourceMappingURL=flash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flash.js","sourceRoot":"","sources":["../../src/flash/flash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAA6D,MAAM,eAAe,CAAC;AAC/H,OAAO,EAAE,iBAAiB,EAA6B,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,WAAW,EAAwB,MAAM,gBAAgB,CAAC;AA4BnE,uEAAuE;AACvE,MAAM,UAAU,QAAQ,CAAC,KAAiB;IACxC,+BAA+B;IAC/B,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAEjD,2EAA2E;IAC3E,mCAAmC;IACnC,MAAM,iBAAiB,GAAiB;QACtC,IAAI,EAAE,KAAK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