@mneme-ai/core 1.68.0 → 1.69.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 (37) hide show
  1. package/dist/hyperscan/bench.d.ts +32 -0
  2. package/dist/hyperscan/bench.d.ts.map +1 -0
  3. package/dist/hyperscan/bench.js +81 -0
  4. package/dist/hyperscan/bench.js.map +1 -0
  5. package/dist/hyperscan/cross_citation.d.ts +51 -0
  6. package/dist/hyperscan/cross_citation.d.ts.map +1 -0
  7. package/dist/hyperscan/cross_citation.js +140 -0
  8. package/dist/hyperscan/cross_citation.js.map +1 -0
  9. package/dist/hyperscan/cross_source_qa.d.ts +49 -0
  10. package/dist/hyperscan/cross_source_qa.d.ts.map +1 -0
  11. package/dist/hyperscan/cross_source_qa.js +219 -0
  12. package/dist/hyperscan/cross_source_qa.js.map +1 -0
  13. package/dist/hyperscan/hyperscan.test.d.ts +5 -0
  14. package/dist/hyperscan/hyperscan.test.d.ts.map +1 -0
  15. package/dist/hyperscan/hyperscan.test.js +191 -0
  16. package/dist/hyperscan/hyperscan.test.js.map +1 -0
  17. package/dist/hyperscan/hyperscan_molecule.d.ts +76 -0
  18. package/dist/hyperscan/hyperscan_molecule.d.ts.map +1 -0
  19. package/dist/hyperscan/hyperscan_molecule.js +144 -0
  20. package/dist/hyperscan/hyperscan_molecule.js.map +1 -0
  21. package/dist/hyperscan/index.d.ts +26 -0
  22. package/dist/hyperscan/index.d.ts.map +1 -0
  23. package/dist/hyperscan/index.js +26 -0
  24. package/dist/hyperscan/index.js.map +1 -0
  25. package/dist/hyperscan/nucleus_dust_htc.d.ts +71 -0
  26. package/dist/hyperscan/nucleus_dust_htc.d.ts.map +1 -0
  27. package/dist/hyperscan/nucleus_dust_htc.js +242 -0
  28. package/dist/hyperscan/nucleus_dust_htc.js.map +1 -0
  29. package/dist/hyperscan/prose_shadow.d.ts +50 -0
  30. package/dist/hyperscan/prose_shadow.d.ts.map +1 -0
  31. package/dist/hyperscan/prose_shadow.js +225 -0
  32. package/dist/hyperscan/prose_shadow.js.map +1 -0
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +10 -0
  36. package/dist/index.js.map +1 -1
  37. package/package.json +1 -1
@@ -0,0 +1,32 @@
1
+ /**
2
+ * v1.69.0 -- HYPERSCAN BENCH.
3
+ *
4
+ * Measures each axis with concrete numbers:
5
+ * H1 prose scan catches the 2 examples the user named (wraith-utils-2099, Sentry-class)
6
+ * H2 cross-citation flags claims with no codebase evidence
7
+ * H3 cross-source fusion lifts trust on questions commits don't fully cover
8
+ * H4 nucleus dust HTC pushes coverage from 0% toward >=80%
9
+ */
10
+ export interface HyperscanBenchResult {
11
+ H1_proseScan: {
12
+ fakesCaught: number;
13
+ totalFakes: number;
14
+ precisionPct: number;
15
+ };
16
+ H2_crossCitation: {
17
+ claimsAudited: number;
18
+ gapsFlagged: number;
19
+ };
20
+ H3_crossSource: {
21
+ questions: number;
22
+ meanTrust: number;
23
+ };
24
+ H4_dustCoverage: {
25
+ coveragePctBefore: number;
26
+ coveragePctAfter: number;
27
+ };
28
+ headline: string;
29
+ }
30
+ export declare function runHyperscanBench(repoRoot: string): HyperscanBenchResult;
31
+ export declare function renderBench(r: HyperscanBenchResult): string;
32
+ //# sourceMappingURL=bench.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bench.d.ts","sourceRoot":"","sources":["../../src/hyperscan/bench.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAChF,gBAAgB,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IACjE,cAAc,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,eAAe,EAAE;QAAE,iBAAiB,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAE,CAAC;IACzE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAqBD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,oBAAoB,CAyCxE;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAW3D"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * v1.69.0 -- HYPERSCAN BENCH.
3
+ *
4
+ * Measures each axis with concrete numbers:
5
+ * H1 prose scan catches the 2 examples the user named (wraith-utils-2099, Sentry-class)
6
+ * H2 cross-citation flags claims with no codebase evidence
7
+ * H3 cross-source fusion lifts trust on questions commits don't fully cover
8
+ * H4 nucleus dust HTC pushes coverage from 0% toward >=80%
9
+ */
10
+ import { proseScan } from "./prose_shadow.js";
11
+ import { crossCitationGround } from "./cross_citation.js";
12
+ import { crossSourceAsk } from "./cross_source_qa.js";
13
+ import { computeCoverage, generateDust } from "./nucleus_dust_htc.js";
14
+ const PROSE_FAKES = [
15
+ "wraith-utils-2099 is integrated for caching", // fake npm
16
+ "We use sentry-fake-99 to track errors across services", // fake observability
17
+ "haunted-payments-9001 handles all our credit card processing", // fake package
18
+ "FakeyMcFakeFace is our production OAuth library", // title-cased fake
19
+ ];
20
+ const PROSE_TRUTHS = [
21
+ "TypeScript powers our type system across the monorepo", // known real
22
+ "React renders the UI components on the frontend", // known real
23
+ ];
24
+ const QUESTIONS = [
25
+ "what is HTC compression and how does it work",
26
+ "how does the AEGIS protocol detect rogue AI",
27
+ "what is the APOPTOSIS protocol",
28
+ "what does the consent kernel guarantee",
29
+ ];
30
+ export function runHyperscanBench(repoRoot) {
31
+ // H1: prose scan
32
+ let fakesCaught = 0;
33
+ for (const claim of PROSE_FAKES) {
34
+ const r = proseScan(repoRoot, claim);
35
+ if (r.suspects.length > 0)
36
+ fakesCaught += 1;
37
+ }
38
+ let truthsFlagged = 0;
39
+ for (const truth of PROSE_TRUTHS) {
40
+ const r = proseScan(repoRoot, truth);
41
+ // Truths SHOULD recognize known names and not list them as suspects.
42
+ if (r.suspects.length > 0 && r.recognized.length === 0)
43
+ truthsFlagged += 1;
44
+ }
45
+ const precisionPct = (fakesCaught / PROSE_FAKES.length) * 100;
46
+ // H2: cross-citation -- audit two fake claims
47
+ const fakeClaim = "WraithMonitor handles our distributed tracing across services and integrates with PhantomMetrics for alerting";
48
+ const audit = crossCitationGround(repoRoot, fakeClaim);
49
+ // H3: cross-source mean trust over a small bench
50
+ let trustSum = 0;
51
+ for (const q of QUESTIONS) {
52
+ const r = crossSourceAsk(repoRoot, q);
53
+ trustSum += r.trust;
54
+ }
55
+ const meanTrust = trustSum / QUESTIONS.length;
56
+ // H4: dust coverage delta
57
+ const before = computeCoverage(repoRoot).coveragePct;
58
+ generateDust(repoRoot);
59
+ const after = computeCoverage(repoRoot).coveragePct;
60
+ const headline = `Hyperscan bench: prose ${precisionPct.toFixed(0)}% caught, citation gaps ${audit.gaps}, mean trust ${(meanTrust * 100).toFixed(0)}%, HTC coverage ${before.toFixed(0)}% -> ${after.toFixed(0)}%.`;
61
+ return {
62
+ H1_proseScan: { fakesCaught, totalFakes: PROSE_FAKES.length, precisionPct },
63
+ H2_crossCitation: { claimsAudited: audit.triples.length, gapsFlagged: audit.gaps },
64
+ H3_crossSource: { questions: QUESTIONS.length, meanTrust },
65
+ H4_dustCoverage: { coveragePctBefore: before, coveragePctAfter: after },
66
+ headline,
67
+ };
68
+ }
69
+ export function renderBench(r) {
70
+ return [
71
+ "HYPERSCAN BENCH -- 4-axis measurable proof",
72
+ "",
73
+ r.headline,
74
+ "",
75
+ `H1 prose scan: ${r.H1_proseScan.fakesCaught}/${r.H1_proseScan.totalFakes} fakes caught (${r.H1_proseScan.precisionPct.toFixed(0)}% precision)`,
76
+ `H2 cross-citation: ${r.H2_crossCitation.gapsFlagged} gap(s) flagged in ${r.H2_crossCitation.claimsAudited} triple(s)`,
77
+ `H3 cross-source QA: mean trust ${(r.H3_crossSource.meanTrust * 100).toFixed(0)}% across ${r.H3_crossSource.questions} questions`,
78
+ `H4 HTC dust coverage: ${r.H4_dustCoverage.coveragePctBefore.toFixed(0)}% -> ${r.H4_dustCoverage.coveragePctAfter.toFixed(0)}% after auto-populate`,
79
+ ].join("\n");
80
+ }
81
+ //# sourceMappingURL=bench.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bench.js","sourceRoot":"","sources":["../../src/hyperscan/bench.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAUtE,MAAM,WAAW,GAAG;IAClB,6CAA6C,EAAkB,WAAW;IAC1E,uDAAuD,EAAS,qBAAqB;IACrF,8DAA8D,EAAE,eAAe;IAC/E,iDAAiD,EAAe,mBAAmB;CACpF,CAAC;AAEF,MAAM,YAAY,GAAG;IACnB,uDAAuD,EAAS,aAAa;IAC7E,iDAAiD,EAAe,aAAa;CAC9E,CAAC;AAEF,MAAM,SAAS,GAAG;IAChB,8CAA8C;IAC9C,6CAA6C;IAC7C,gCAAgC;IAChC,wCAAwC;CACzC,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,iBAAiB;IACjB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YA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CROSS-CITATION GROUND.
3
+ *
4
+ * Wild idea: every behavior-attribution in a claim ("X handles Y", "we
5
+ * use Z for Q") implies a citation should EXIST. We can't trust prose
6
+ * naming a thing; we can verify whether the thing is reachable in the
7
+ * codebase under the claimed role.
8
+ *
9
+ * Algorithm:
10
+ * 1. Parse claim into (subject, verb, object) triples using a tiny
11
+ * verb-anchored grammar.
12
+ * 2. For each triple, search:
13
+ * a. Files matching subject as filename / module-name
14
+ * b. Imports of subject as module
15
+ * c. Comment/docstring mentions of subject co-occurring with object
16
+ * 3. Citation density = (sources-with-evidence / sources-checked).
17
+ * Below threshold -> citation-gap suspect.
18
+ *
19
+ * Output: per-triple citation report.
20
+ */
21
+ export interface ClaimTriple {
22
+ subject: string;
23
+ verb: string;
24
+ object: string;
25
+ }
26
+ export interface CitationCheck {
27
+ triple: ClaimTriple;
28
+ /** Sources where evidence was found. */
29
+ evidence: string[];
30
+ /** Sources we checked. */
31
+ checked: number;
32
+ /** evidence.length / checked. */
33
+ density: number;
34
+ /** Whether the citation gap is significant. */
35
+ isGap: boolean;
36
+ detail: string;
37
+ }
38
+ export interface CrossCitationReport {
39
+ triples: ClaimTriple[];
40
+ checks: CitationCheck[];
41
+ /** Triples with density < threshold. */
42
+ gaps: number;
43
+ /** Overall ground score 0..1. */
44
+ groundScore: number;
45
+ ms: number;
46
+ }
47
+ export declare function parseTriples(claim: string): ClaimTriple[];
48
+ export declare function crossCitationGround(repoRoot: string, claim: string, opts?: {
49
+ gapThreshold?: number;
50
+ }): CrossCitationReport;
51
+ //# sourceMappingURL=cross_citation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross_citation.d.ts","sourceRoot":"","sources":["../../src/hyperscan/cross_citation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAcH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,WAAW,CAAC;IACpB,wCAAwC;IACxC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,CAczD;AAqDD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,mBAAmB,CA4B1H"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * v1.69.0 -- HYPERSCAN H2: CROSS-CITATION GROUND.
3
+ *
4
+ * Wild idea: every behavior-attribution in a claim ("X handles Y", "we
5
+ * use Z for Q") implies a citation should EXIST. We can't trust prose
6
+ * naming a thing; we can verify whether the thing is reachable in the
7
+ * codebase under the claimed role.
8
+ *
9
+ * Algorithm:
10
+ * 1. Parse claim into (subject, verb, object) triples using a tiny
11
+ * verb-anchored grammar.
12
+ * 2. For each triple, search:
13
+ * a. Files matching subject as filename / module-name
14
+ * b. Imports of subject as module
15
+ * c. Comment/docstring mentions of subject co-occurring with object
16
+ * 3. Citation density = (sources-with-evidence / sources-checked).
17
+ * Below threshold -> citation-gap suspect.
18
+ *
19
+ * Output: per-triple citation report.
20
+ */
21
+ import { readFileSync, readdirSync, statSync } from "node:fs";
22
+ import { join } from "node:path";
23
+ const BEHAVIOR_VERBS = [
24
+ "handles?", "implements?", "uses?", "calls?", "covers?", "supports?",
25
+ "tests?", "validates?", "enforces?", "verifies?", "caches?", "stores?",
26
+ "manages?", "powers?", "drives?", "controls?", "integrates with",
27
+ "depends on", "is used by", "is integrated for",
28
+ ];
29
+ const VERB_RE = new RegExp(`\\b(\\S+(?:\\s+\\S+)?)\\s+(${BEHAVIOR_VERBS.join("|")})\\s+(.+?)(?:[.,;!?]|$)`, "gi");
30
+ export function parseTriples(claim) {
31
+ const out = [];
32
+ const seen = new Set();
33
+ for (const m of claim.matchAll(VERB_RE)) {
34
+ const subject = (m[1] ?? "").trim();
35
+ const verb = (m[2] ?? "").trim();
36
+ const object = (m[3] ?? "").trim().split(/\s+/).slice(0, 5).join(" "); // cap noun phrase
37
+ if (subject.length < 2 || object.length < 2)
38
+ continue;
39
+ const key = `${subject.toLowerCase()}|${verb}|${object.toLowerCase()}`;
40
+ if (seen.has(key))
41
+ continue;
42
+ seen.add(key);
43
+ out.push({ subject, verb, object });
44
+ }
45
+ return out;
46
+ }
47
+ function walkSourceFiles(repoRoot, max = 200) {
48
+ const out = [];
49
+ const skip = new Set(["node_modules", ".git", "dist", "build", ".mneme", "coverage"]);
50
+ const walk = (dir) => {
51
+ if (out.length >= max)
52
+ return;
53
+ let entries = [];
54
+ try {
55
+ entries = readdirSync(dir);
56
+ }
57
+ catch {
58
+ return;
59
+ }
60
+ for (const e of entries) {
61
+ if (skip.has(e))
62
+ continue;
63
+ const p = join(dir, e);
64
+ try {
65
+ const s = statSync(p);
66
+ if (s.isDirectory())
67
+ walk(p);
68
+ else if (/\.(ts|tsx|js|mjs|cjs|md)$/.test(e)) {
69
+ try {
70
+ out.push({ path: p, content: readFileSync(p, "utf8") });
71
+ }
72
+ catch { /* */ }
73
+ }
74
+ }
75
+ catch { /* */ }
76
+ }
77
+ };
78
+ walk(repoRoot);
79
+ return out;
80
+ }
81
+ function tokens(s) {
82
+ return new Set((s.toLowerCase().match(/[a-z][a-z0-9_-]+/g) ?? []).filter((t) => t.length >= 3));
83
+ }
84
+ function searchEvidence(triple, files) {
85
+ const evidence = [];
86
+ const subjTokens = tokens(triple.subject);
87
+ const objTokens = tokens(triple.object);
88
+ if (subjTokens.size === 0 || objTokens.size === 0)
89
+ return evidence;
90
+ for (const f of files) {
91
+ const fileName = f.path.split(/[\\/]/).pop().toLowerCase();
92
+ const contentLower = f.content.toLowerCase();
93
+ // Filename match for subject
94
+ if ([...subjTokens].some((t) => fileName.includes(t))) {
95
+ evidence.push(`filename:${fileName}`);
96
+ if (evidence.length >= 5)
97
+ return evidence;
98
+ continue;
99
+ }
100
+ // Subject + object co-occurrence in file
101
+ if ([...subjTokens].some((t) => contentLower.includes(t)) &&
102
+ [...objTokens].some((t) => contentLower.includes(t))) {
103
+ evidence.push(`cooccur:${fileName}`);
104
+ if (evidence.length >= 5)
105
+ return evidence;
106
+ }
107
+ }
108
+ return evidence;
109
+ }
110
+ export function crossCitationGround(repoRoot, claim, opts) {
111
+ const t0 = Date.now();
112
+ const gapThreshold = opts?.gapThreshold ?? 0.3;
113
+ const triples = parseTriples(claim);
114
+ const files = walkSourceFiles(repoRoot);
115
+ const checks = [];
116
+ let gaps = 0;
117
+ let totalDensity = 0;
118
+ for (const triple of triples) {
119
+ const evidence = searchEvidence(triple, files);
120
+ const checked = Math.min(files.length, 50);
121
+ const density = checked === 0 ? 0 : evidence.length / Math.max(1, Math.min(5, checked));
122
+ const isGap = density < gapThreshold;
123
+ if (isGap)
124
+ gaps += 1;
125
+ totalDensity += density;
126
+ checks.push({
127
+ triple,
128
+ evidence,
129
+ checked,
130
+ density,
131
+ isGap,
132
+ detail: isGap
133
+ ? `Citation gap: "${triple.subject} ${triple.verb} ${triple.object}" -- ${evidence.length}/${checked} sources confirm.`
134
+ : `Grounded: ${evidence.length} citation(s) found for "${triple.subject} ${triple.verb} ...".`,
135
+ });
136
+ }
137
+ const groundScore = triples.length === 0 ? 1 : 1 - (gaps / triples.length);
138
+ return { triples, checks, gaps, groundScore, ms: Date.now() - t0 };
139
+ }
140
+ //# sourceMappingURL=cross_citation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross_citation.js","sourceRoot":"","sources":["../../src/hyperscan/cross_citation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAc,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,cAAc,GAAG;IACrB,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW;IACpE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS;IACtE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB;IAChE,YAAY,EAAE,YAAY,EAAE,mBAAmB;CAChD,CAAC;AAEF,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,8BAA8B,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAC;AA+BlH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,MAAM,GAAG,GAAkB,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,I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,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC;AACrE,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * v1.69.0 -- HYPERSCAN H3: CROSS-SOURCE Q&A FUSION.
3
+ *
4
+ * Wild idea: when commit messages don't fully describe a feature
5
+ * (HTC was named only AFTER its first commit, so commit search for
6
+ * "HTC compression" returns weak results), Mneme should NOT just
7
+ * trust commit retrieval. Fuse retrieval across N orthogonal sources:
8
+ *
9
+ * 1. Commit subjects + bodies (existing)
10
+ * 2. README.md sections (existing-ish)
11
+ * 3. CHANGELOG.md entries (NEW - structured release notes)
12
+ * 4. Source-file top docstrings (NEW - module docs)
13
+ * 5. package.json description (NEW - terse, but authoritative)
14
+ *
15
+ * Each source scored independently via TF-Jaccard. Final trust is a
16
+ * weighted fusion. When sources align (high cross-source agreement),
17
+ * trust is HIGH. When they diverge, trust drops but we report all
18
+ * sources so the user can see what each says.
19
+ *
20
+ * The wild bit: SHAPE-SHIFTING. The "winning answer" is constructed
21
+ * by taking the BEST sentence from EACH source and stitching them
22
+ * into a multi-witness reply.
23
+ */
24
+ export type SourceKind = "commit" | "readme" | "changelog" | "docstring" | "package-json";
25
+ export interface SourceHit {
26
+ source: SourceKind;
27
+ citation: string;
28
+ excerpt: string;
29
+ score: number;
30
+ }
31
+ export interface FusedAnswer {
32
+ question: string;
33
+ hits: SourceHit[];
34
+ /** Sources that contributed at least one hit. */
35
+ sourcesPresent: SourceKind[];
36
+ /** Fused trust 0..1. */
37
+ trust: number;
38
+ trustLabel: "HIGH" | "MEDIUM" | "LOW";
39
+ /** The stitched multi-witness answer (best snippet per source). */
40
+ fusedAnswer: string;
41
+ /** Per-source max score (for transparency). */
42
+ perSourceMax: Record<SourceKind, number>;
43
+ ms: number;
44
+ }
45
+ export declare function crossSourceAsk(repoRoot: string, question: string, opts?: {
46
+ maxCommits?: number;
47
+ maxFiles?: number;
48
+ }): FusedAnswer;
49
+ //# sourceMappingURL=cross_source_qa.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross_source_qa.d.ts","sourceRoot":"","sources":["../../src/hyperscan/cross_source_qa.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,GAAG,cAAc,CAAC;AAE1F,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,SAAS,EAAE,CAAC;IAClB,iDAAiD;IACjD,cAAc,EAAE,UAAU,EAAE,CAAC;IAC7B,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,YAAY,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACzC,EAAE,EAAE,MAAM,CAAC;CACZ;AA8ED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,CA+FjI"}
@@ -0,0 +1,219 @@
1
+ /**
2
+ * v1.69.0 -- HYPERSCAN H3: CROSS-SOURCE Q&A FUSION.
3
+ *
4
+ * Wild idea: when commit messages don't fully describe a feature
5
+ * (HTC was named only AFTER its first commit, so commit search for
6
+ * "HTC compression" returns weak results), Mneme should NOT just
7
+ * trust commit retrieval. Fuse retrieval across N orthogonal sources:
8
+ *
9
+ * 1. Commit subjects + bodies (existing)
10
+ * 2. README.md sections (existing-ish)
11
+ * 3. CHANGELOG.md entries (NEW - structured release notes)
12
+ * 4. Source-file top docstrings (NEW - module docs)
13
+ * 5. package.json description (NEW - terse, but authoritative)
14
+ *
15
+ * Each source scored independently via TF-Jaccard. Final trust is a
16
+ * weighted fusion. When sources align (high cross-source agreement),
17
+ * trust is HIGH. When they diverge, trust drops but we report all
18
+ * sources so the user can see what each says.
19
+ *
20
+ * The wild bit: SHAPE-SHIFTING. The "winning answer" is constructed
21
+ * by taking the BEST sentence from EACH source and stitching them
22
+ * into a multi-witness reply.
23
+ */
24
+ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
25
+ import { join } from "node:path";
26
+ import { execSync } from "node:child_process";
27
+ const STOPWORDS = new Set([
28
+ "the", "and", "for", "with", "this", "that", "from", "into", "when", "then",
29
+ "function", "const", "var", "let", "true", "false", "null", "return", "import", "export",
30
+ "type", "interface", "class", "public", "private", "static", "async", "await",
31
+ "what", "how", "why", "where", "which", "who", "use", "uses", "used",
32
+ ]);
33
+ function tokenize(s) {
34
+ return new Set((s.toLowerCase().match(/[a-z][a-z0-9_-]+/g) ?? []).filter((t) => t.length >= 3 && !STOPWORDS.has(t)));
35
+ }
36
+ function jaccard(a, b) {
37
+ if (a.size === 0 || b.size === 0)
38
+ return 0;
39
+ let inter = 0;
40
+ for (const x of a)
41
+ if (b.has(x))
42
+ inter += 1;
43
+ return inter / (a.size + b.size - inter);
44
+ }
45
+ function readMaybeFile(p) {
46
+ if (!existsSync(p))
47
+ return "";
48
+ try {
49
+ return readFileSync(p, "utf8");
50
+ }
51
+ catch {
52
+ return "";
53
+ }
54
+ }
55
+ function readCommitSubjects(repoRoot, max = 500) {
56
+ try {
57
+ const r = execSync(`git -C "${repoRoot}" log --max-count=${max} --pretty=format:%s%n%b%n---`, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 3000 });
58
+ return r.split(/\n---\n/).map((s) => s.trim()).filter(Boolean);
59
+ }
60
+ catch {
61
+ return [];
62
+ }
63
+ }
64
+ function splitSentences(text) {
65
+ return text.split(/(?<=[.!?])\s+(?=[A-Z])/).map((s) => s.trim()).filter((s) => s.length >= 10);
66
+ }
67
+ function rankSnippets(query, source, text, citation) {
68
+ const sentences = splitSentences(text);
69
+ const hits = [];
70
+ for (const sent of sentences) {
71
+ const score = jaccard(query, tokenize(sent));
72
+ if (score >= 0.1)
73
+ hits.push({ source, citation, excerpt: sent.slice(0, 280), score });
74
+ }
75
+ hits.sort((a, b) => b.score - a.score);
76
+ return hits.slice(0, 3);
77
+ }
78
+ function readSourceDocstrings(repoRoot, max = 50) {
79
+ const out = [];
80
+ const skip = new Set(["node_modules", ".git", "dist", "build", ".mneme"]);
81
+ const walk = (dir) => {
82
+ if (out.length >= max)
83
+ return;
84
+ let entries = [];
85
+ try {
86
+ entries = readdirSync(dir);
87
+ }
88
+ catch {
89
+ return;
90
+ }
91
+ for (const e of entries) {
92
+ if (skip.has(e))
93
+ continue;
94
+ const p = join(dir, e);
95
+ try {
96
+ const s = statSync(p);
97
+ if (s.isDirectory())
98
+ walk(p);
99
+ else if (/\.ts$/.test(e)) {
100
+ let content = "";
101
+ try {
102
+ content = readFileSync(p, "utf8");
103
+ }
104
+ catch {
105
+ continue;
106
+ }
107
+ // Top-of-file docstring: `/** ... */` at the very start.
108
+ const m = content.match(/^\s*\/\*\*([\s\S]*?)\*\//);
109
+ if (m)
110
+ out.push({ path: p, doc: m[1].replace(/^\s*\*/gm, "").trim() });
111
+ if (out.length >= max)
112
+ return;
113
+ }
114
+ }
115
+ catch { /* */ }
116
+ }
117
+ };
118
+ walk(repoRoot);
119
+ return out;
120
+ }
121
+ export function crossSourceAsk(repoRoot, question, opts) {
122
+ const t0 = Date.now();
123
+ const query = tokenize(question);
124
+ const hits = [];
125
+ // 1. Commits
126
+ for (const commit of readCommitSubjects(repoRoot, opts?.maxCommits ?? 500)) {
127
+ const ranked = rankSnippets(query, "commit", commit, "commit");
128
+ for (const h of ranked.slice(0, 1))
129
+ hits.push(h);
130
+ if (hits.length >= 60)
131
+ break;
132
+ }
133
+ // 2. README
134
+ const readme = readMaybeFile(join(repoRoot, "README.md"));
135
+ if (readme)
136
+ hits.push(...rankSnippets(query, "readme", readme, "README.md"));
137
+ // 3. CHANGELOG
138
+ const changelog = readMaybeFile(join(repoRoot, "CHANGELOG.md"));
139
+ if (changelog)
140
+ hits.push(...rankSnippets(query, "changelog", changelog, "CHANGELOG.md"));
141
+ // 4. Docstrings
142
+ for (const { path, doc } of readSourceDocstrings(repoRoot, opts?.maxFiles ?? 50)) {
143
+ const ranked = rankSnippets(query, "docstring", doc, path.split(/[\\/]/).slice(-2).join("/"));
144
+ hits.push(...ranked.slice(0, 1));
145
+ }
146
+ // 5. package.json description
147
+ const pkgRaw = readMaybeFile(join(repoRoot, "package.json"));
148
+ if (pkgRaw) {
149
+ try {
150
+ const pkg = JSON.parse(pkgRaw);
151
+ const desc = String(pkg["description"] ?? "");
152
+ if (desc)
153
+ hits.push(...rankSnippets(query, "package-json", desc, "package.json"));
154
+ }
155
+ catch { /* */ }
156
+ }
157
+ // Per-source max scores.
158
+ const perSourceMax = { commit: 0, readme: 0, changelog: 0, docstring: 0, "package-json": 0 };
159
+ const presentSources = new Set();
160
+ for (const h of hits) {
161
+ if (h.score > perSourceMax[h.source])
162
+ perSourceMax[h.source] = h.score;
163
+ presentSources.add(h.source);
164
+ }
165
+ // Trust fusion: weighted avg of per-source max, weighted by source authority.
166
+ const WEIGHTS = {
167
+ docstring: 1.2, // module-level intent
168
+ changelog: 1.1, // structured release notes
169
+ readme: 1.0, // canonical user-facing doc
170
+ commit: 0.8, // many noisy entries
171
+ "package-json": 0.6, // terse but authoritative
172
+ };
173
+ let weightedSum = 0, weightSum = 0;
174
+ for (const k of Object.keys(perSourceMax)) {
175
+ const w = WEIGHTS[k];
176
+ weightedSum += perSourceMax[k] * w;
177
+ weightSum += w;
178
+ }
179
+ const baseTrust = weightSum === 0 ? 0 : weightedSum / weightSum;
180
+ // Cross-source agreement boost: 2+ sources with >= 0.2 -> +0.15.
181
+ const strongSources = Object.values(perSourceMax).filter((v) => v >= 0.2).length;
182
+ const agreementBoost = strongSources >= 3 ? 0.25 : strongSources >= 2 ? 0.15 : 0;
183
+ const trust = Math.min(1, baseTrust * 2 + agreementBoost); // *2 because Jaccard is naturally low
184
+ let trustLabel;
185
+ if (trust >= 0.7)
186
+ trustLabel = "HIGH";
187
+ else if (trust >= 0.4)
188
+ trustLabel = "MEDIUM";
189
+ else
190
+ trustLabel = "LOW";
191
+ // Build fused answer: top snippet from each source that contributed.
192
+ const bestPerSource = new Map();
193
+ for (const h of hits) {
194
+ const prev = bestPerSource.get(h.source);
195
+ if (!prev || h.score > prev.score)
196
+ bestPerSource.set(h.source, h);
197
+ }
198
+ const fusedLines = [];
199
+ for (const k of ["docstring", "changelog", "readme", "commit", "package-json"]) {
200
+ const h = bestPerSource.get(k);
201
+ if (h && h.score >= 0.1)
202
+ fusedLines.push(`[${k}@${h.citation}] ${h.excerpt}`);
203
+ }
204
+ const fusedAnswer = fusedLines.length === 0
205
+ ? "(no source had sufficient overlap with the question; trust LOW)"
206
+ : fusedLines.join("\n\n");
207
+ hits.sort((a, b) => b.score - a.score);
208
+ return {
209
+ question,
210
+ hits: hits.slice(0, 10),
211
+ sourcesPresent: [...presentSources],
212
+ trust,
213
+ trustLabel,
214
+ fusedAnswer,
215
+ perSourceMax,
216
+ ms: Date.now() - t0,
217
+ };
218
+ }
219
+ //# sourceMappingURL=cross_source_qa.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross_source_qa.js","sourceRoot":"","sources":["../../src/hyperscan/cross_source_qa.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E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,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACpE,CAAC;IACD,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,KAAK,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,CAAiB,EAAE,CAAC;QAC/F,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,GAAG;YAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAChF,CAAC;IACD,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,KAAK,CAAC;QACzC,CAAC,CAAC,iEAAiE;QACnE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5B,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IACvC,OAAO;QACL,QAAQ;QACR,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;QACvB,cAAc,EAAE,CAAC,GAAG,cAAc,CAAC;QACnC,KAAK;QACL,UAAU;QACV,WAAW;QACX,YAAY;QACZ,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE;KACpB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * v1.69.0 -- HYPERSCAN PROTOCOL test suite.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=hyperscan.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hyperscan.test.d.ts","sourceRoot":"","sources":["../../src/hyperscan/hyperscan.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}