@mneme-ai/core 1.77.0 → 1.79.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/agent_manifest.d.ts +1 -1
- package/dist/agent_manifest.d.ts.map +1 -1
- package/dist/agent_manifest.js +8 -1
- package/dist/agent_manifest.js.map +1 -1
- package/dist/genesplice/genesplice.test.js +3 -2
- package/dist/genesplice/genesplice.test.js.map +1 -1
- package/dist/genesplice/soul_prompt.d.ts.map +1 -1
- package/dist/genesplice/soul_prompt.js +3 -0
- package/dist/genesplice/soul_prompt.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/lattice/dictionary.d.ts +29 -0
- package/dist/lattice/dictionary.d.ts.map +1 -0
- package/dist/lattice/dictionary.js +81 -0
- package/dist/lattice/dictionary.js.map +1 -0
- package/dist/lattice/grounding_score.d.ts +46 -0
- package/dist/lattice/grounding_score.d.ts.map +1 -0
- package/dist/lattice/grounding_score.js +125 -0
- package/dist/lattice/grounding_score.js.map +1 -0
- package/dist/lattice/index.d.ts +5 -0
- package/dist/lattice/index.d.ts.map +1 -0
- package/dist/lattice/index.js +5 -0
- package/dist/lattice/index.js.map +1 -0
- package/dist/lattice/intent_atoms.d.ts +40 -0
- package/dist/lattice/intent_atoms.d.ts.map +1 -0
- package/dist/lattice/intent_atoms.js +166 -0
- package/dist/lattice/intent_atoms.js.map +1 -0
- package/dist/lattice/lattice.test.d.ts +2 -0
- package/dist/lattice/lattice.test.d.ts.map +1 -0
- package/dist/lattice/lattice.test.js +148 -0
- package/dist/lattice/lattice.test.js.map +1 -0
- package/dist/lattice/pulse_contract.d.ts +30 -0
- package/dist/lattice/pulse_contract.d.ts.map +1 -0
- package/dist/lattice/pulse_contract.js +54 -0
- package/dist/lattice/pulse_contract.js.map +1 -0
- package/dist/neuron/auto_atoms.d.ts +28 -0
- package/dist/neuron/auto_atoms.d.ts.map +1 -0
- package/dist/neuron/auto_atoms.js +39 -0
- package/dist/neuron/auto_atoms.js.map +1 -0
- package/dist/neuron/fuzzy.d.ts +27 -0
- package/dist/neuron/fuzzy.d.ts.map +1 -0
- package/dist/neuron/fuzzy.js +51 -0
- package/dist/neuron/fuzzy.js.map +1 -0
- package/dist/neuron/index.d.ts +17 -0
- package/dist/neuron/index.d.ts.map +1 -0
- package/dist/neuron/index.js +17 -0
- package/dist/neuron/index.js.map +1 -0
- package/dist/neuron/neuron.test.d.ts +2 -0
- package/dist/neuron/neuron.test.d.ts.map +1 -0
- package/dist/neuron/neuron.test.js +137 -0
- package/dist/neuron/neuron.test.js.map +1 -0
- package/dist/neuron/oracle.d.ts +50 -0
- package/dist/neuron/oracle.d.ts.map +1 -0
- package/dist/neuron/oracle.js +76 -0
- package/dist/neuron/oracle.js.map +1 -0
- package/dist/neuron/triage.d.ts +43 -0
- package/dist/neuron/triage.d.ts.map +1 -0
- package/dist/neuron/triage.js +91 -0
- package/dist/neuron/triage.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.79.0 -- NEURON: TELEPATHIC TRIAGE.
|
|
3
|
+
*
|
|
4
|
+
* The molecule of intelligence. Receives a user prompt + a tool
|
|
5
|
+
* catalog, and routes it via 4 stacked strategies (each independent):
|
|
6
|
+
*
|
|
7
|
+
* 1. EXACT LATTICE -- hand-crafted intent atoms, priority=absolute
|
|
8
|
+
* 2. AUTO-DERIVED -- every tool's triggers[] becomes a fallback atom
|
|
9
|
+
* 3. FUZZY TRIGRAM -- Jaccard similarity for near-matches
|
|
10
|
+
* 4. KEYWORD BIAS -- prompt mentions "mneme" / "soul" / "version" etc.
|
|
11
|
+
*
|
|
12
|
+
* Returns a ranked list of {tool, confidence, strategy, reason}.
|
|
13
|
+
* If the top result is `absolute` (strategy = exact lattice), AI must
|
|
14
|
+
* obey. Otherwise it can pick the top candidate or surface 2-3 for
|
|
15
|
+
* the user.
|
|
16
|
+
*
|
|
17
|
+
* NEW WILDEST FUNCTION (nobody dares to ship this): even when no
|
|
18
|
+
* direct match, NEURON returns a confidence-weighted "best guess"
|
|
19
|
+
* with a `confusion: true` flag so the AI knows to ask the user.
|
|
20
|
+
*/
|
|
21
|
+
import { routeIntent, INTENT_ATOMS } from "../lattice/intent_atoms.js";
|
|
22
|
+
import { rankByFuzzy } from "./fuzzy.js";
|
|
23
|
+
import { deriveAtomsFromCatalog, mergeAtoms } from "./auto_atoms.js";
|
|
24
|
+
const MNEME_KEYWORD_RE = /\b(mneme|soul prompt|ส่งสมอง)\b/i;
|
|
25
|
+
const FUZZY_THRESHOLD = 0.20;
|
|
26
|
+
/** Run the full 4-strategy triage. */
|
|
27
|
+
export function telepathicTriage(userPrompt, toolCatalog = []) {
|
|
28
|
+
if (!userPrompt || !userPrompt.trim()) {
|
|
29
|
+
return {
|
|
30
|
+
recommended: null,
|
|
31
|
+
candidates: [],
|
|
32
|
+
confusion: false,
|
|
33
|
+
summary: "empty prompt -- nothing to route",
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const candidates = [];
|
|
37
|
+
// Strategy 1: exact lattice (hand-crafted, absolute priority wins).
|
|
38
|
+
const latticeMatch = routeIntent(userPrompt);
|
|
39
|
+
if (latticeMatch) {
|
|
40
|
+
candidates.push({
|
|
41
|
+
tool: latticeMatch.atom.tool,
|
|
42
|
+
confidence: latticeMatch.absolute ? 1.0 : 0.85,
|
|
43
|
+
strategy: "exact-lattice",
|
|
44
|
+
reason: `hand-crafted intent atom matched "${latticeMatch.matchedTrigger}"`,
|
|
45
|
+
matchedTrigger: latticeMatch.matchedTrigger,
|
|
46
|
+
intent: latticeMatch.atom.intent,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// Strategy 2 + 3: auto-derived atoms from tool catalog (fuzzy ranked).
|
|
50
|
+
const autoAtoms = deriveAtomsFromCatalog(toolCatalog);
|
|
51
|
+
const allAtoms = mergeAtoms(INTENT_ATOMS, autoAtoms);
|
|
52
|
+
const fuzzyRanked = rankByFuzzy(userPrompt, allAtoms.map((a) => ({ item: a, triggers: a.triggers })), FUZZY_THRESHOLD);
|
|
53
|
+
const seenTools = new Set(candidates.map((c) => c.tool));
|
|
54
|
+
for (const r of fuzzyRanked.slice(0, 5)) {
|
|
55
|
+
if (seenTools.has(r.item.tool))
|
|
56
|
+
continue;
|
|
57
|
+
const isAutoDerived = autoAtoms.some((a) => a.tool === r.item.tool);
|
|
58
|
+
candidates.push({
|
|
59
|
+
tool: r.item.tool,
|
|
60
|
+
confidence: Math.min(0.85, r.similarity + 0.1),
|
|
61
|
+
strategy: isAutoDerived ? "auto-derived" : "fuzzy-trigram",
|
|
62
|
+
reason: `trigram similarity ${(r.similarity * 100).toFixed(0)}% to "${r.matched}"`,
|
|
63
|
+
matchedTrigger: r.matched,
|
|
64
|
+
intent: r.item.intent,
|
|
65
|
+
});
|
|
66
|
+
seenTools.add(r.item.tool);
|
|
67
|
+
}
|
|
68
|
+
// Strategy 4: keyword bias -- prompt mentions Mneme generally,
|
|
69
|
+
// suggest the most likely tool (system.upgrade if "update", etc.)
|
|
70
|
+
if (candidates.length === 0 && MNEME_KEYWORD_RE.test(userPrompt)) {
|
|
71
|
+
candidates.push({
|
|
72
|
+
tool: "mneme.lattice.route",
|
|
73
|
+
confidence: 0.3,
|
|
74
|
+
strategy: "keyword-bias",
|
|
75
|
+
reason: "prompt mentions Mneme but no atom matched -- route via lattice for disambiguation",
|
|
76
|
+
intent: "ask the user what they want",
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
candidates.sort((a, b) => b.confidence - a.confidence);
|
|
80
|
+
const recommended = candidates[0] ?? null;
|
|
81
|
+
const confusion = !recommended ||
|
|
82
|
+
recommended.confidence < 0.7 ||
|
|
83
|
+
(candidates.length >= 2 && candidates[0].confidence - candidates[1].confidence < 0.1);
|
|
84
|
+
const summary = recommended
|
|
85
|
+
? confusion
|
|
86
|
+
? `${candidates.length} candidates -- top: ${recommended.tool} @ ${(recommended.confidence * 100).toFixed(0)}% (ASK USER, low confidence or tied)`
|
|
87
|
+
: `route to ${recommended.tool} @ ${(recommended.confidence * 100).toFixed(0)}% via ${recommended.strategy}`
|
|
88
|
+
: "no route found";
|
|
89
|
+
return { recommended, candidates, confusion, summary };
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=triage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triage.js","sourceRoot":"","sources":["../../src/neuron/triage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAmB,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAC;AAwBpF,MAAM,gBAAgB,GAAG,kCAAkC,CAAC;AAC5D,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B,sCAAsC;AACtC,MAAM,UAAU,gBAAgB,CAC9B,UAAkB,EAClB,cAAmC,EAAE;IAErC,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC;QACtC,OAAO;YACL,WAAW,EAAE,IAAI;YACjB,UAAU,EAAE,EAAE;YACd,SAAS,EAAE,KAAK;YAChB,OAAO,EAAE,kCAAkC;SAC5C,CAAC;IACJ,CAAC;IACD,MAAM,UAAU,GAAsB,EAAE,CAAC;IAEzC,oEAAoE;IACpE,MAAM,YAAY,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;IAC7C,IAAI,YAAY,EAAE,CAAC;QACjB,UAAU,CAAC,IAAI,CAAC;YACd,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI;YAC5B,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,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