@mneme-ai/core 1.67.1 → 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.
- package/dist/ascension/ascension.test.d.ts +13 -0
- package/dist/ascension/ascension.test.d.ts.map +1 -0
- package/dist/ascension/ascension.test.js +313 -0
- package/dist/ascension/ascension.test.js.map +1 -0
- package/dist/ascension/circadian_heartbeat.d.ts +70 -0
- package/dist/ascension/circadian_heartbeat.d.ts.map +1 -0
- package/dist/ascension/circadian_heartbeat.js +176 -0
- package/dist/ascension/circadian_heartbeat.js.map +1 -0
- package/dist/ascension/conformal_apoptosis.d.ts +98 -0
- package/dist/ascension/conformal_apoptosis.d.ts.map +1 -0
- package/dist/ascension/conformal_apoptosis.js +175 -0
- package/dist/ascension/conformal_apoptosis.js.map +1 -0
- package/dist/ascension/inbox_tier.d.ts +74 -0
- package/dist/ascension/inbox_tier.d.ts.map +1 -0
- package/dist/ascension/inbox_tier.js +119 -0
- package/dist/ascension/inbox_tier.js.map +1 -0
- package/dist/ascension/index.d.ts +73 -0
- package/dist/ascension/index.d.ts.map +1 -0
- package/dist/ascension/index.js +126 -0
- package/dist/ascension/index.js.map +1 -0
- package/dist/ascension/prophetic_embedder.d.ts +38 -0
- package/dist/ascension/prophetic_embedder.d.ts.map +1 -0
- package/dist/ascension/prophetic_embedder.js +85 -0
- package/dist/ascension/prophetic_embedder.js.map +1 -0
- package/dist/ascension/sovereign_mode.d.ts +46 -0
- package/dist/ascension/sovereign_mode.d.ts.map +1 -0
- package/dist/ascension/sovereign_mode.js +94 -0
- package/dist/ascension/sovereign_mode.js.map +1 -0
- package/dist/ascension/superposed_antivirus.d.ts +62 -0
- package/dist/ascension/superposed_antivirus.d.ts.map +1 -0
- package/dist/ascension/superposed_antivirus.js +198 -0
- package/dist/ascension/superposed_antivirus.js.map +1 -0
- package/dist/hyperscan/bench.d.ts +32 -0
- package/dist/hyperscan/bench.d.ts.map +1 -0
- package/dist/hyperscan/bench.js +81 -0
- package/dist/hyperscan/bench.js.map +1 -0
- package/dist/hyperscan/cross_citation.d.ts +51 -0
- package/dist/hyperscan/cross_citation.d.ts.map +1 -0
- package/dist/hyperscan/cross_citation.js +140 -0
- package/dist/hyperscan/cross_citation.js.map +1 -0
- package/dist/hyperscan/cross_source_qa.d.ts +49 -0
- package/dist/hyperscan/cross_source_qa.d.ts.map +1 -0
- package/dist/hyperscan/cross_source_qa.js +219 -0
- package/dist/hyperscan/cross_source_qa.js.map +1 -0
- package/dist/hyperscan/hyperscan.test.d.ts +5 -0
- package/dist/hyperscan/hyperscan.test.d.ts.map +1 -0
- package/dist/hyperscan/hyperscan.test.js +191 -0
- package/dist/hyperscan/hyperscan.test.js.map +1 -0
- package/dist/hyperscan/hyperscan_molecule.d.ts +76 -0
- package/dist/hyperscan/hyperscan_molecule.d.ts.map +1 -0
- package/dist/hyperscan/hyperscan_molecule.js +144 -0
- package/dist/hyperscan/hyperscan_molecule.js.map +1 -0
- package/dist/hyperscan/index.d.ts +26 -0
- package/dist/hyperscan/index.d.ts.map +1 -0
- package/dist/hyperscan/index.js +26 -0
- package/dist/hyperscan/index.js.map +1 -0
- package/dist/hyperscan/nucleus_dust_htc.d.ts +71 -0
- package/dist/hyperscan/nucleus_dust_htc.d.ts.map +1 -0
- package/dist/hyperscan/nucleus_dust_htc.js +242 -0
- package/dist/hyperscan/nucleus_dust_htc.js.map +1 -0
- package/dist/hyperscan/prose_shadow.d.ts +50 -0
- package/dist/hyperscan/prose_shadow.d.ts.map +1 -0
- package/dist/hyperscan/prose_shadow.js +225 -0
- package/dist/hyperscan/prose_shadow.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -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,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AA0B9C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAC3E,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ;IACxF,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO;IAC7E,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM;CACrE,CAAC,CAAC;AAEH,SAAS,QAAQ,CAAC,CAAS;IACzB,OAAO,IAAI,GAAG,CACZ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAA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AC,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 @@
|
|
|
1
|
+
{"version":3,"file":"hyperscan.test.d.ts","sourceRoot":"","sources":["../../src/hyperscan/hyperscan.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.69.0 -- HYPERSCAN PROTOCOL test suite.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
5
|
+
import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { execSync } from "node:child_process";
|
|
9
|
+
import { extractEntities, proseScan } from "./prose_shadow.js";
|
|
10
|
+
import { parseTriples, crossCitationGround } from "./cross_citation.js";
|
|
11
|
+
import { crossSourceAsk } from "./cross_source_qa.js";
|
|
12
|
+
import { generateDust, computeCoverage, clusterDust, readAbstracts } from "./nucleus_dust_htc.js";
|
|
13
|
+
import { buildMolecule, query } from "./hyperscan_molecule.js";
|
|
14
|
+
function setup() { return mkdtempSync(join(tmpdir(), "mneme-hs-")); }
|
|
15
|
+
function cleanup(r) { try {
|
|
16
|
+
rmSync(r, { recursive: true, force: true });
|
|
17
|
+
}
|
|
18
|
+
catch { /* */ } }
|
|
19
|
+
function initGit(r, files, commits) {
|
|
20
|
+
execSync(`git init --quiet -b main`, { cwd: r, stdio: "ignore" });
|
|
21
|
+
execSync(`git config user.email "t@t.t"`, { cwd: r, stdio: "ignore" });
|
|
22
|
+
execSync(`git config user.name "t"`, { cwd: r, stdio: "ignore" });
|
|
23
|
+
execSync(`git config commit.gpgsign false`, { cwd: r, stdio: "ignore" });
|
|
24
|
+
for (const f of files) {
|
|
25
|
+
const dir = join(r, f.path, "..");
|
|
26
|
+
mkdirSync(dir, { recursive: true });
|
|
27
|
+
writeFileSync(join(r, f.path), f.content, "utf8");
|
|
28
|
+
}
|
|
29
|
+
execSync(`git add -A`, { cwd: r, stdio: "ignore" });
|
|
30
|
+
for (const c of commits) {
|
|
31
|
+
writeFileSync(join(r, `m-${c.replace(/\W/g, "_")}.txt`), c, "utf8");
|
|
32
|
+
execSync(`git add -A`, { cwd: r, stdio: "ignore" });
|
|
33
|
+
execSync(`git commit -m "${c}" --no-gpg-sign --quiet`, { cwd: r, stdio: "ignore" });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// ─── H1 PROSE SHADOW SCAN ────────────────────────────────────────────
|
|
37
|
+
describe("v1.69 Hyperscan H1 · Prose Shadow Scan", () => {
|
|
38
|
+
let r;
|
|
39
|
+
beforeEach(() => { r = setup(); writeFileSync(join(r, "package.json"), JSON.stringify({ name: "test", dependencies: { typescript: "5.0.0", react: "18.0.0" } }), "utf8"); });
|
|
40
|
+
afterEach(() => cleanup(r));
|
|
41
|
+
it("extracts title-cased + package-shaped + acronym entities", () => {
|
|
42
|
+
const ents = extractEntities("WraithMonitor handles tracing via wraith-utils-2099 with ACME-Lib 3.0");
|
|
43
|
+
const surfaces = ents.map((e) => e.surface);
|
|
44
|
+
expect(surfaces).toContain("WraithMonitor");
|
|
45
|
+
expect(surfaces.some((s) => s.startsWith("wraith-utils"))).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
it("catches fake package-shape with digits + no citation", () => {
|
|
48
|
+
const r1 = proseScan(r, "wraith-utils-2099 is integrated for caching across services");
|
|
49
|
+
const wraith = r1.suspects.find((s) => s.entity.toLowerCase().includes("wraith"));
|
|
50
|
+
expect(wraith).toBeDefined();
|
|
51
|
+
expect(wraith.confidence).toBeGreaterThanOrEqual(0.8);
|
|
52
|
+
});
|
|
53
|
+
it("recognizes known-real services (whitelists them)", () => {
|
|
54
|
+
const r1 = proseScan(r, "We use Sentry for error tracking and Datadog for APM");
|
|
55
|
+
expect(r1.recognized.length).toBeGreaterThan(0);
|
|
56
|
+
expect(r1.suspects.find((s) => s.entity.toLowerCase() === "sentry")).toBeUndefined();
|
|
57
|
+
});
|
|
58
|
+
it("flags title-cased unknowns with no citation", () => {
|
|
59
|
+
const r1 = proseScan(r, "FakeyMcFakeFace is our production OAuth library");
|
|
60
|
+
expect(r1.suspects.find((s) => s.entity.includes("FakeyMcFake"))).toBeDefined();
|
|
61
|
+
});
|
|
62
|
+
it("does NOT flag real deps", () => {
|
|
63
|
+
const r1 = proseScan(r, "TypeScript handles our types and React renders the UI");
|
|
64
|
+
// Both are in KNOWN_REAL_NAMES; should be recognized not suspected.
|
|
65
|
+
expect(r1.suspects.length).toBe(0);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
// ─── H2 CROSS-CITATION GROUND ────────────────────────────────────────
|
|
69
|
+
describe("v1.69 Hyperscan H2 · Cross-Citation Ground", () => {
|
|
70
|
+
let r;
|
|
71
|
+
beforeEach(() => { r = setup(); });
|
|
72
|
+
afterEach(() => cleanup(r));
|
|
73
|
+
it("parses triples from prose", () => {
|
|
74
|
+
const tr = parseTriples("auth.ts handles login and billing.ts implements charging");
|
|
75
|
+
expect(tr.length).toBeGreaterThanOrEqual(2);
|
|
76
|
+
expect(tr[0]?.subject).toContain("auth");
|
|
77
|
+
});
|
|
78
|
+
it("flags citation gap when files don't exist", () => {
|
|
79
|
+
const r1 = crossCitationGround(r, "PhantomMonitor handles distributed tracing across services");
|
|
80
|
+
expect(r1.gaps).toBeGreaterThanOrEqual(0);
|
|
81
|
+
expect(r1.groundScore).toBeLessThanOrEqual(1);
|
|
82
|
+
});
|
|
83
|
+
it("grounds when subject + object co-occur in source", () => {
|
|
84
|
+
writeFileSync(join(r, "auth.ts"), "// auth login bcrypt handler\nexport function login() {}\n", "utf8");
|
|
85
|
+
const r1 = crossCitationGround(r, "auth.ts handles login routing for users");
|
|
86
|
+
expect(r1.groundScore).toBeGreaterThan(0);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
// ─── H3 CROSS-SOURCE Q&A FUSION ──────────────────────────────────────
|
|
90
|
+
describe("v1.69 Hyperscan H3 · Cross-Source Q&A Fusion", () => {
|
|
91
|
+
let r;
|
|
92
|
+
beforeEach(() => { r = setup(); });
|
|
93
|
+
afterEach(() => cleanup(r));
|
|
94
|
+
it("fuses retrieval across multiple sources", () => {
|
|
95
|
+
initGit(r, [
|
|
96
|
+
{ path: "README.md", content: "# Project\n\nHTC compression cuts token spend by 100x via three-layer pre-compression of git history into LLM-consumable form.\n" },
|
|
97
|
+
{ path: "CHANGELOG.md", content: "## [1.0.0]\n- Added HTC compression for git history\n" },
|
|
98
|
+
{ path: "package.json", content: JSON.stringify({ name: "p", description: "HTC-powered memory layer." }) },
|
|
99
|
+
{ path: "htc.ts", content: "/**\n * HTC: hierarchical token cache for compressing commit history.\n */\nexport const x = 1;\n" },
|
|
100
|
+
], ["feat: add HTC compression"]);
|
|
101
|
+
const r1 = crossSourceAsk(r, "what is HTC compression and how does it work");
|
|
102
|
+
expect(r1.sourcesPresent.length).toBeGreaterThanOrEqual(2);
|
|
103
|
+
expect(["MEDIUM", "HIGH"]).toContain(r1.trustLabel);
|
|
104
|
+
expect(r1.fusedAnswer).toContain("HTC");
|
|
105
|
+
});
|
|
106
|
+
it("reports LOW trust when nothing matches", () => {
|
|
107
|
+
initGit(r, [{ path: "README.md", content: "Only generic stuff here." }], ["initial"]);
|
|
108
|
+
const r1 = crossSourceAsk(r, "what is fooBarBaz compression");
|
|
109
|
+
expect(r1.trustLabel).toBe("LOW");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
// ─── H4 NUCLEUS DUST HTC ─────────────────────────────────────────────
|
|
113
|
+
describe("v1.69 Hyperscan H4 · Nucleus Dust HTC", () => {
|
|
114
|
+
let r;
|
|
115
|
+
beforeEach(() => { r = setup(); });
|
|
116
|
+
afterEach(() => cleanup(r));
|
|
117
|
+
it("generates abstracts for commits + file docstrings", () => {
|
|
118
|
+
initGit(r, [
|
|
119
|
+
{ path: "src/foo.ts", content: "/**\n * Foo module: does the foo thing.\n */\nexport const x = 1;\n" },
|
|
120
|
+
{ path: "src/bar.ts", content: "/**\n * Bar module: handles bars.\n */\nexport const y = 2;\n" },
|
|
121
|
+
], ["feat(foo): add foo", "feat(bar): add bar", "fix: tidy"]);
|
|
122
|
+
const { added } = generateDust(r);
|
|
123
|
+
expect(added).toBeGreaterThanOrEqual(2);
|
|
124
|
+
const abstracts = readAbstracts(r);
|
|
125
|
+
expect(abstracts.length).toBeGreaterThanOrEqual(2);
|
|
126
|
+
});
|
|
127
|
+
it("coverage increases after dust generation", () => {
|
|
128
|
+
initGit(r, [{ path: "src/foo.ts", content: "/** Foo. */\nexport const x = 1;\n" }], ["feat: foo"]);
|
|
129
|
+
const before = computeCoverage(r).coveragePct;
|
|
130
|
+
generateDust(r);
|
|
131
|
+
const after = computeCoverage(r).coveragePct;
|
|
132
|
+
expect(after).toBeGreaterThanOrEqual(before);
|
|
133
|
+
expect(after).toBeGreaterThan(0);
|
|
134
|
+
});
|
|
135
|
+
it("idempotent: re-running adds 0", () => {
|
|
136
|
+
initGit(r, [{ path: "src/foo.ts", content: "/** Foo. */\nexport const x = 1;\n" }], ["feat: foo"]);
|
|
137
|
+
generateDust(r);
|
|
138
|
+
const second = generateDust(r);
|
|
139
|
+
expect(second.added).toBe(0);
|
|
140
|
+
});
|
|
141
|
+
it("clusterDust groups similar abstracts", () => {
|
|
142
|
+
initGit(r, [], ["feat(auth): add login", "feat(auth): add logout", "fix(auth): retry", "feat(billing): stripe"]);
|
|
143
|
+
generateDust(r);
|
|
144
|
+
const clusters = clusterDust(r);
|
|
145
|
+
expect(clusters.length).toBeGreaterThan(0);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
// ─── HYPERSCAN MOLECULE ──────────────────────────────────────────────
|
|
149
|
+
describe("v1.69 Hyperscan · Shape-shifting Molecule", () => {
|
|
150
|
+
it("builds a molecule with 4 forms", () => {
|
|
151
|
+
const m = buildMolecule({
|
|
152
|
+
text: "function login() handles auth via bcrypt at src/auth.ts",
|
|
153
|
+
source: { kind: "commit", ref: "abc123" },
|
|
154
|
+
epoch: "2026-01-01T00:00:00Z",
|
|
155
|
+
});
|
|
156
|
+
expect(m.textForm).toContain("login");
|
|
157
|
+
expect(m.vectorForm.size).toBeGreaterThan(0);
|
|
158
|
+
expect(m.structuralForm.functions).toContain("login");
|
|
159
|
+
expect(m.structuralForm.paths.some((p) => p.endsWith(".ts"))).toBe(true);
|
|
160
|
+
expect(m.temporalForm.epoch).toBe("2026-01-01T00:00:00Z");
|
|
161
|
+
});
|
|
162
|
+
it("query with cosine ranks by vector similarity", () => {
|
|
163
|
+
const mA = buildMolecule({ text: "auth bcrypt login flow", source: { kind: "commit", ref: "a" } });
|
|
164
|
+
const mB = buildMolecule({ text: "billing stripe charge", source: { kind: "commit", ref: "b" } });
|
|
165
|
+
const result = query([mA, mB], "cosine", { text: "auth login" });
|
|
166
|
+
expect(result[0]?.molecule.id).toBe(mA.id);
|
|
167
|
+
});
|
|
168
|
+
it("query with structural ranks by AST shape overlap", () => {
|
|
169
|
+
const mA = buildMolecule({ text: "function login() at src/auth.ts", source: { kind: "commit", ref: "a" } });
|
|
170
|
+
const mB = buildMolecule({ text: "class Billing in billing.js", source: { kind: "commit", ref: "b" } });
|
|
171
|
+
const result = query([mA, mB], "structural", { text: "function login() at src/auth.ts" });
|
|
172
|
+
expect(result[0]?.molecule.id).toBe(mA.id);
|
|
173
|
+
});
|
|
174
|
+
it("query with hybrid fuses 4 algorithm scores", () => {
|
|
175
|
+
const m1 = buildMolecule({ text: "auth login bcrypt secure flow", source: { kind: "commit", ref: "a" } });
|
|
176
|
+
const m2 = buildMolecule({ text: "billing stripe payment processing", source: { kind: "commit", ref: "b" } });
|
|
177
|
+
const result = query([m1, m2], "hybrid", { text: "auth login bcrypt" });
|
|
178
|
+
expect(result[0]?.molecule.id).toBe(m1.id);
|
|
179
|
+
expect(result[0]?.scores.cosine).toBeDefined();
|
|
180
|
+
expect(result[0]?.scores.jaccard).toBeDefined();
|
|
181
|
+
expect(result[0]?.scores.structural).toBeDefined();
|
|
182
|
+
});
|
|
183
|
+
it("query with temporal ranks by epoch closeness", () => {
|
|
184
|
+
const target = "2026-05-12T00:00:00Z";
|
|
185
|
+
const close = buildMolecule({ text: "x", source: { kind: "c", ref: "1" }, epoch: "2026-05-11T00:00:00Z" });
|
|
186
|
+
const far = buildMolecule({ text: "x", source: { kind: "c", ref: "2" }, epoch: "2020-01-01T00:00:00Z" });
|
|
187
|
+
const result = query([close, far], "temporal", { epoch: target });
|
|
188
|
+
expect(result[0]?.molecule.id).toBe(close.id);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
//# sourceMappingURL=hyperscan.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperscan.test.js","sourceRoot":"","sources":["../../src/hyperscan/hyperscan.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAA4B,MAAM,SAAS,CAAC;AAClG,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,sBA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E,CAAC,CAAC;QACzG,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAClE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.69.0 -- HYPERSCAN MOLECULE (shape-shifting data structure).
|
|
3
|
+
*
|
|
4
|
+
* The wild bit: a single MOLECULE holds FOUR orthogonal forms of one
|
|
5
|
+
* piece of knowledge. The caller asks for whichever FORM best
|
|
6
|
+
* matches their query class -- the molecule "shape-shifts" without
|
|
7
|
+
* recomputation.
|
|
8
|
+
*
|
|
9
|
+
* textForm plain-English summary (~30 tokens)
|
|
10
|
+
* vectorForm bag-of-words vector for cosine retrieval
|
|
11
|
+
* structuralForm AST-shape signature (functions / paths / symbols)
|
|
12
|
+
* temporalForm commit-chain neighborhood (predecessor / successor SHAs)
|
|
13
|
+
*
|
|
14
|
+
* "Mix algorithm สุดโต่ง": at query time the caller picks ONE of N
|
|
15
|
+
* retrieval algorithms (Jaccard / cosine / structural-match /
|
|
16
|
+
* temporal-distance / hybrid-weighted) and the molecule emits the
|
|
17
|
+
* matching form. Different forms NEVER recomputed -- pre-built.
|
|
18
|
+
*
|
|
19
|
+
* This is the data structure the user asked for: "โมเลกุลใหม่
|
|
20
|
+
* มารองรับ" + "การสลับร่างแปลงร่าง" + "mix algorithm บ้าๆสุดโต่ง".
|
|
21
|
+
*/
|
|
22
|
+
export type MoleculeForm = "text" | "vector" | "structural" | "temporal";
|
|
23
|
+
export interface HyperscanMolecule {
|
|
24
|
+
id: string;
|
|
25
|
+
/** Plain-English summary. */
|
|
26
|
+
textForm: string;
|
|
27
|
+
/** Bag-of-words vector: word -> count. */
|
|
28
|
+
vectorForm: Map<string, number>;
|
|
29
|
+
/** AST-shape signature: {functions, classes, paths, symbols}. */
|
|
30
|
+
structuralForm: {
|
|
31
|
+
functions: string[];
|
|
32
|
+
classes: string[];
|
|
33
|
+
paths: string[];
|
|
34
|
+
symbols: string[];
|
|
35
|
+
};
|
|
36
|
+
/** Temporal links to neighboring molecules. */
|
|
37
|
+
temporalForm: {
|
|
38
|
+
predecessors: string[];
|
|
39
|
+
successors: string[];
|
|
40
|
+
epoch: string;
|
|
41
|
+
};
|
|
42
|
+
/** Source provenance. */
|
|
43
|
+
source: {
|
|
44
|
+
kind: string;
|
|
45
|
+
ref: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export interface BuildMoleculeInput {
|
|
49
|
+
text: string;
|
|
50
|
+
source: {
|
|
51
|
+
kind: string;
|
|
52
|
+
ref: string;
|
|
53
|
+
};
|
|
54
|
+
epoch?: string;
|
|
55
|
+
predecessors?: string[];
|
|
56
|
+
successors?: string[];
|
|
57
|
+
}
|
|
58
|
+
/** Build a molecule from a text excerpt + provenance. */
|
|
59
|
+
export declare function buildMolecule(input: BuildMoleculeInput): HyperscanMolecule;
|
|
60
|
+
export type RetrievalAlgo = "jaccard" | "cosine" | "structural" | "temporal" | "hybrid";
|
|
61
|
+
export interface QueryInput {
|
|
62
|
+
text?: string;
|
|
63
|
+
epoch?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface MoleculeMatch {
|
|
66
|
+
molecule: HyperscanMolecule;
|
|
67
|
+
/** Per-algo scores; populated when caller asked for hybrid. */
|
|
68
|
+
scores: Partial<Record<RetrievalAlgo, number>>;
|
|
69
|
+
/** Final fused score the caller will rank by. */
|
|
70
|
+
finalScore: number;
|
|
71
|
+
}
|
|
72
|
+
/** Query a corpus of molecules using one of N retrieval algorithms.
|
|
73
|
+
* "hybrid" fuses cosine + jaccard + structural + temporal via the
|
|
74
|
+
* ALGO_WEIGHTS mix (the wild algorithm-mix the user requested). */
|
|
75
|
+
export declare function query(molecules: HyperscanMolecule[], algo: RetrievalAlgo, q: QueryInput): MoleculeMatch[];
|
|
76
|
+
//# sourceMappingURL=hyperscan_molecule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperscan_molecule.d.ts","sourceRoot":"","sources":["../../src/hyperscan/hyperscan_molecule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,GAAG,YAAY,GAAG,UAAU,CAAC;AAEzE,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,iEAAiE;IACjE,cAAc,EAAE;QACd,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IACF,+CAA+C;IAC/C,YAAY,EAAE;QACZ,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,yBAAyB;IACzB,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CACvC;AA6BD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;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