@mneme-ai/core 1.76.0 → 1.78.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/abyss/homunculus.d.ts.map +1 -1
- package/dist/abyss/homunculus.js +20 -9
- package/dist/abyss/homunculus.js.map +1 -1
- package/dist/agent_manifest.d.ts +1 -1
- package/dist/agent_manifest.d.ts.map +1 -1
- package/dist/agent_manifest.js +9 -1
- package/dist/agent_manifest.js.map +1 -1
- package/dist/genesplice/soul_prompt.d.ts.map +1 -1
- package/dist/genesplice/soul_prompt.js +7 -1
- 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 +8 -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/parasite/bridge.d.ts.map +1 -1
- package/dist/parasite/bridge.js +3 -0
- package/dist/parasite/bridge.js.map +1 -1
- package/dist/seamless/index.d.ts +2 -0
- package/dist/seamless/index.d.ts.map +1 -0
- package/dist/seamless/index.js +2 -0
- package/dist/seamless/index.js.map +1 -0
- package/dist/seamless/seamless.test.d.ts +2 -0
- package/dist/seamless/seamless.test.d.ts.map +1 -0
- package/dist/seamless/seamless.test.js +100 -0
- package/dist/seamless/seamless.test.js.map +1 -0
- package/dist/seamless/voice_directive.d.ts +62 -0
- package/dist/seamless/voice_directive.d.ts.map +1 -0
- package/dist/seamless/voice_directive.js +161 -0
- package/dist/seamless/voice_directive.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.78.0 -- LATTICE: Grounding Score (0-100 across 5 measurable axes).
|
|
3
|
+
*
|
|
4
|
+
* Quantifies how "grounded" an AI's interpretation of a user prompt is.
|
|
5
|
+
* Higher = less context bleed, more intent-faithful, fewer codename
|
|
6
|
+
* leaks. The user can demand a 90+ grounding score before trusting a
|
|
7
|
+
* cross-vendor reply.
|
|
8
|
+
*
|
|
9
|
+
* Axes (each 0-20):
|
|
10
|
+
* 1. intent_match -- did we find a high-confidence intent atom?
|
|
11
|
+
* 2. context_purity -- did the AI ignore prior unrelated topics?
|
|
12
|
+
* 3. pulse_compliance -- did the user match a pulse contract trigger?
|
|
13
|
+
* 4. codename_silence -- does the AI's reply avoid Mneme codenames?
|
|
14
|
+
* 5. response_clarity -- short, no menus, no version chatter?
|
|
15
|
+
*/
|
|
16
|
+
import { routeIntent } from "./intent_atoms.js";
|
|
17
|
+
import { lintReply } from "../seamless/voice_directive.js";
|
|
18
|
+
import { matchPulseContract } from "./pulse_contract.js";
|
|
19
|
+
const MNEME_KEYWORDS = ["mneme", "mneme-ai", "soul prompt", "ส่งสมอง"];
|
|
20
|
+
function mentionsMneme(s) {
|
|
21
|
+
const lower = s.toLowerCase();
|
|
22
|
+
return MNEME_KEYWORDS.some((k) => lower.includes(k));
|
|
23
|
+
}
|
|
24
|
+
export function scoreGrounding(input) {
|
|
25
|
+
const notes = [];
|
|
26
|
+
// 2. context_purity (0-20) -- computed first because intent_match
|
|
27
|
+
// depends on it (if AI ignored the intent in favor of prior topic,
|
|
28
|
+
// intent_match drops to 0).
|
|
29
|
+
let context_purity = 20;
|
|
30
|
+
let highBleed = false;
|
|
31
|
+
if (mentionsMneme(input.userPrompt) && input.priorContext) {
|
|
32
|
+
const priorMentionsMneme = mentionsMneme(input.priorContext);
|
|
33
|
+
if (!priorMentionsMneme) {
|
|
34
|
+
const replyTokens = input.aiReply.toLowerCase().split(/\s+/).filter(Boolean);
|
|
35
|
+
const priorTokens = new Set(input.priorContext.toLowerCase().split(/\s+/).filter((w) => w.length > 4));
|
|
36
|
+
const bleed = replyTokens.filter((t) => priorTokens.has(t)).length;
|
|
37
|
+
const ratio = replyTokens.length === 0 ? 0 : bleed / replyTokens.length;
|
|
38
|
+
if (ratio > 0.30) {
|
|
39
|
+
context_purity = 5;
|
|
40
|
+
highBleed = true;
|
|
41
|
+
notes.push(`context bleed: ${Math.round(ratio * 100)}% of reply tokens from prior turn`);
|
|
42
|
+
}
|
|
43
|
+
else if (ratio > 0.15) {
|
|
44
|
+
context_purity = 12;
|
|
45
|
+
notes.push(`some context bleed: ${Math.round(ratio * 100)}%`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
notes.push(`context purity good: ${Math.round(ratio * 100)}% overlap`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// 1. intent_match (0-20) -- found atom AND honored it
|
|
53
|
+
const matched = routeIntent(input.userPrompt);
|
|
54
|
+
let intent_match = 0;
|
|
55
|
+
if (matched) {
|
|
56
|
+
if (highBleed) {
|
|
57
|
+
// AI ignored the intent and drifted back to prior topic -- 0.
|
|
58
|
+
intent_match = 0;
|
|
59
|
+
notes.push(`intent IGNORED: matched ${matched.atom.intent} but reply drifted to prior context`);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
intent_match = matched.absolute ? 20 : matched.atom.priority === "strong" ? 14 : 8;
|
|
63
|
+
notes.push(`intent atom matched: ${matched.atom.intent} (${matched.atom.priority})`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
notes.push("no intent atom matched -- AI free to interpret");
|
|
68
|
+
intent_match = 8;
|
|
69
|
+
}
|
|
70
|
+
// 3. pulse_compliance (0-20). Credit when user matched a contract
|
|
71
|
+
// trigger AND the AI honored the intent (intent_match high).
|
|
72
|
+
let pulse_compliance = 10;
|
|
73
|
+
let contract = null;
|
|
74
|
+
if (input.pulseContracts && input.pulseContracts.length > 0) {
|
|
75
|
+
contract = matchPulseContract(input.pulseContracts, input.userPrompt);
|
|
76
|
+
if (contract) {
|
|
77
|
+
const honored = intent_match >= 14;
|
|
78
|
+
pulse_compliance = honored ? 20 : 0;
|
|
79
|
+
notes.push(honored
|
|
80
|
+
? `pulse contract honored: "${contract.trigger}" → ${contract.promisedAction}`
|
|
81
|
+
: `PULSE CONTRACT VIOLATED: user said "${contract.trigger}" but reply did not honor intent`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
pulse_compliance = 10;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// 4. codename_silence (0-20)
|
|
88
|
+
const lint = lintReply(input.aiReply);
|
|
89
|
+
const codenameIssues = lint.issues.filter((i) => i.rule === "codename").length;
|
|
90
|
+
const otherIssues = lint.issues.length - codenameIssues;
|
|
91
|
+
let codename_silence = 20;
|
|
92
|
+
codename_silence -= codenameIssues * 7;
|
|
93
|
+
codename_silence -= otherIssues * 3;
|
|
94
|
+
codename_silence = Math.max(0, codename_silence);
|
|
95
|
+
if (lint.issueCount > 0)
|
|
96
|
+
notes.push(`voice violations: ${lint.summary}`);
|
|
97
|
+
// 5. response_clarity (0-20)
|
|
98
|
+
let response_clarity = 20;
|
|
99
|
+
const wordCount = input.aiReply.split(/\s+/).filter(Boolean).length;
|
|
100
|
+
if (wordCount > 400) {
|
|
101
|
+
response_clarity -= 10;
|
|
102
|
+
notes.push(`long reply: ${wordCount} words`);
|
|
103
|
+
}
|
|
104
|
+
else if (wordCount > 200) {
|
|
105
|
+
response_clarity -= 5;
|
|
106
|
+
}
|
|
107
|
+
// Penalize menu offers in the reply.
|
|
108
|
+
if (/\b(would you like me to|shall I run|do you want me to)\b/i.test(input.aiReply)) {
|
|
109
|
+
response_clarity -= 8;
|
|
110
|
+
notes.push("menu offer detected");
|
|
111
|
+
}
|
|
112
|
+
response_clarity = Math.max(0, response_clarity);
|
|
113
|
+
const total = intent_match + context_purity + pulse_compliance + codename_silence + response_clarity;
|
|
114
|
+
const summary = `Grounding ${total}/100 · intent ${intent_match}/20 · context ${context_purity}/20 · pulse ${pulse_compliance}/20 · silence ${codename_silence}/20 · clarity ${response_clarity}/20`;
|
|
115
|
+
return {
|
|
116
|
+
total,
|
|
117
|
+
axes: { intent_match, context_purity, pulse_compliance, codename_silence, response_clarity },
|
|
118
|
+
matched,
|
|
119
|
+
contract,
|
|
120
|
+
lint,
|
|
121
|
+
notes,
|
|
122
|
+
summary,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=grounding_score.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grounding_score.js","sourceRoot":"","sources":["../../src/lattice/grounding_score.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAwB,MAAM,gCAAgC,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAsB,MAAM,qBAAqB,CAAC;AA8B7E,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;AAEvE,SAAS,aAAa,CAAC,CAAS;IAC9B,MAAM,K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|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lattice/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lattice/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.78.0 -- LATTICE: Intent Atom Catalog.
|
|
3
|
+
*
|
|
4
|
+
* Hardcoded {trigger phrase → Mneme tool} map. When user input matches
|
|
5
|
+
* any trigger, the AI MUST route to that tool BEFORE blending with
|
|
6
|
+
* conversational context. Stops the "update mneme ดีไหม" → "let me
|
|
7
|
+
* optimize your One Piece shipping" disaster.
|
|
8
|
+
*
|
|
9
|
+
* Priority levels:
|
|
10
|
+
* absolute -- single trigger phrase locks the intent; no conversation
|
|
11
|
+
* context can override it.
|
|
12
|
+
* strong -- prefer this routing unless explicit cue says otherwise.
|
|
13
|
+
* advisory -- one of N likely intents; AI can disambiguate.
|
|
14
|
+
*/
|
|
15
|
+
export type IntentPriority = "absolute" | "strong" | "advisory";
|
|
16
|
+
export interface IntentAtom {
|
|
17
|
+
/** Trigger phrases (case-insensitive substring matches). Include
|
|
18
|
+
* Thai + English + common typos / shortenings. */
|
|
19
|
+
triggers: readonly string[];
|
|
20
|
+
/** Mneme tool to route to. Use the full `mneme.*` name. */
|
|
21
|
+
tool: string;
|
|
22
|
+
/** How firmly the AI should obey this routing. */
|
|
23
|
+
priority: IntentPriority;
|
|
24
|
+
/** Short plain-English label for the intent. */
|
|
25
|
+
intent: string;
|
|
26
|
+
/** What the AI should say while running (in Thai+English). */
|
|
27
|
+
promise?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare const INTENT_ATOMS: readonly IntentAtom[];
|
|
30
|
+
export interface IntentMatch {
|
|
31
|
+
atom: IntentAtom;
|
|
32
|
+
matchedTrigger: string;
|
|
33
|
+
/** 0..1 confidence -- length of matched trigger / length of input. */
|
|
34
|
+
confidence: number;
|
|
35
|
+
/** True if the matched atom is priority=absolute. */
|
|
36
|
+
absolute: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Find the best-matching intent atom for a user prompt, or null. */
|
|
39
|
+
export declare function routeIntent(userText: string): IntentMatch | null;
|
|
40
|
+
//# sourceMappingURL=intent_atoms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent_atoms.d.ts","sourceRoot":"","sources":["../../src/lattice/intent_atoms.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEhE,MAAM,WAAW,UAAU;IACzB;uDACmD;IACnD,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,QAAQ,EAAE,cAAc,CAAC;IACzB,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,YAAY,EAAE,SAAS,UAAU,EA4G7C,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAUD,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CA8BhE"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.78.0 -- LATTICE: Intent Atom Catalog.
|
|
3
|
+
*
|
|
4
|
+
* Hardcoded {trigger phrase → Mneme tool} map. When user input matches
|
|
5
|
+
* any trigger, the AI MUST route to that tool BEFORE blending with
|
|
6
|
+
* conversational context. Stops the "update mneme ดีไหม" → "let me
|
|
7
|
+
* optimize your One Piece shipping" disaster.
|
|
8
|
+
*
|
|
9
|
+
* Priority levels:
|
|
10
|
+
* absolute -- single trigger phrase locks the intent; no conversation
|
|
11
|
+
* context can override it.
|
|
12
|
+
* strong -- prefer this routing unless explicit cue says otherwise.
|
|
13
|
+
* advisory -- one of N likely intents; AI can disambiguate.
|
|
14
|
+
*/
|
|
15
|
+
export const INTENT_ATOMS = [
|
|
16
|
+
// ─── System: upgrade ────────────────────────────────────────────────
|
|
17
|
+
{
|
|
18
|
+
triggers: [
|
|
19
|
+
"update mneme",
|
|
20
|
+
"upgrade mneme",
|
|
21
|
+
"อัปเดต mneme",
|
|
22
|
+
"อัปเกรด mneme",
|
|
23
|
+
"อัพเดต mneme",
|
|
24
|
+
"อัพเกรด mneme",
|
|
25
|
+
"update mneme ดีไหม",
|
|
26
|
+
"upgrade mneme ดีไหม",
|
|
27
|
+
"mneme เวอร์ชั่นใหม่",
|
|
28
|
+
"ลง mneme version ใหม่",
|
|
29
|
+
"mneme is behind",
|
|
30
|
+
"mneme out of date",
|
|
31
|
+
],
|
|
32
|
+
tool: "mneme.system.upgrade",
|
|
33
|
+
priority: "absolute",
|
|
34
|
+
intent: "upgrade the local Mneme installation to the latest npm version",
|
|
35
|
+
promise: "อัปเกรด Mneme ให้ครับ — one moment.",
|
|
36
|
+
},
|
|
37
|
+
// ─── Cross-vendor handoff (soul prompt) ─────────────────────────────
|
|
38
|
+
{
|
|
39
|
+
triggers: [
|
|
40
|
+
"ส่งสมอง",
|
|
41
|
+
"ส่งสมองให้",
|
|
42
|
+
"hand off brain",
|
|
43
|
+
"hand off to",
|
|
44
|
+
"continue in chatgpt",
|
|
45
|
+
"continue in gemini",
|
|
46
|
+
"continue in claude",
|
|
47
|
+
"soul prompt",
|
|
48
|
+
"transfer this conversation",
|
|
49
|
+
"ย้ายสมองไป",
|
|
50
|
+
"ส่งบทสนทนาให้",
|
|
51
|
+
],
|
|
52
|
+
tool: "mneme.genesplice.soul-prompt",
|
|
53
|
+
priority: "absolute",
|
|
54
|
+
intent: "generate a paste-able soul prompt to continue this conversation in another AI",
|
|
55
|
+
promise: "กำลังบีบ context เป็น soul prompt — paste ปลายทางได้เลย.",
|
|
56
|
+
},
|
|
57
|
+
// ─── Version check ──────────────────────────────────────────────────
|
|
58
|
+
{
|
|
59
|
+
triggers: [
|
|
60
|
+
"what version is mneme",
|
|
61
|
+
"mneme version",
|
|
62
|
+
"เวอร์ชั่นอะไร",
|
|
63
|
+
"is mneme up to date",
|
|
64
|
+
"are we on the latest",
|
|
65
|
+
"mneme ล่าสุด",
|
|
66
|
+
"ตรวจเวอร์ชั่น",
|
|
67
|
+
"ตรวจสอบเวอร์ชั่น mneme",
|
|
68
|
+
],
|
|
69
|
+
tool: "mneme.telepathy.heartbeat",
|
|
70
|
+
priority: "absolute",
|
|
71
|
+
intent: "report current Mneme version + npm-latest comparison",
|
|
72
|
+
promise: "เช็ค heartbeat ครับ.",
|
|
73
|
+
},
|
|
74
|
+
// ─── Capsule cleanup ────────────────────────────────────────────────
|
|
75
|
+
{
|
|
76
|
+
triggers: ["prune capsules", "clean capsule", "ลบ capsule เก่า", "capsule dir บวม"],
|
|
77
|
+
tool: "mneme.abyss.scythe.prune",
|
|
78
|
+
priority: "absolute",
|
|
79
|
+
intent: "prune .mneme/capsules/ via TTL + count cap",
|
|
80
|
+
},
|
|
81
|
+
// ─── Voice lint (escalated to absolute) ─────────────────────────────
|
|
82
|
+
{
|
|
83
|
+
triggers: ["lint voice", "scan reply for jargon", "เช็คเสียง AI", "AI พูดศัพท์ภายใน"],
|
|
84
|
+
tool: "mneme.seamless.lint",
|
|
85
|
+
priority: "absolute",
|
|
86
|
+
intent: "scan an AI draft reply for Mneme codename / mode-narration violations",
|
|
87
|
+
},
|
|
88
|
+
// ─── Soul archive ───────────────────────────────────────────────────
|
|
89
|
+
{
|
|
90
|
+
triggers: ["save this brain", "archive this soul", "soul history", "show past handovers", "เก็บสมองไว้"],
|
|
91
|
+
tool: "mneme.abyss.revenant.archive",
|
|
92
|
+
priority: "strong",
|
|
93
|
+
intent: "archive the current soul prompt for later replay",
|
|
94
|
+
},
|
|
95
|
+
// ─── Voice lint ─────────────────────────────────────────────────────
|
|
96
|
+
{
|
|
97
|
+
triggers: ["lint this reply", "voice check", "check my draft", "AI พูดศัพท์ใน"],
|
|
98
|
+
tool: "mneme.seamless.lint",
|
|
99
|
+
priority: "strong",
|
|
100
|
+
intent: "scan an AI draft for codename / mode-narration / version-chatter violations",
|
|
101
|
+
},
|
|
102
|
+
// ─── Memory: ask ────────────────────────────────────────────────────
|
|
103
|
+
{
|
|
104
|
+
triggers: ["why does this code", "who introduced", "what's the history of", "ทำไม code นี้"],
|
|
105
|
+
tool: "mneme.memory.ask",
|
|
106
|
+
priority: "strong",
|
|
107
|
+
intent: "answer a 'why / who / what' question from git memory",
|
|
108
|
+
},
|
|
109
|
+
// ─── Apoptosis ──────────────────────────────────────────────────────
|
|
110
|
+
{
|
|
111
|
+
triggers: [
|
|
112
|
+
"verify this claim",
|
|
113
|
+
"fact check this",
|
|
114
|
+
"is this a hallucination",
|
|
115
|
+
"AI โกหก",
|
|
116
|
+
"AI ฮัลลู",
|
|
117
|
+
"check ai output",
|
|
118
|
+
],
|
|
119
|
+
tool: "mneme.apoptosis.detect",
|
|
120
|
+
priority: "strong",
|
|
121
|
+
intent: "fire 7-oracle hallucination detector",
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
function normalize(s) {
|
|
125
|
+
return s
|
|
126
|
+
.toLowerCase()
|
|
127
|
+
.replace(/[?!.,;:"'`]+/g, " ")
|
|
128
|
+
.replace(/\s+/g, " ")
|
|
129
|
+
.trim();
|
|
130
|
+
}
|
|
131
|
+
/** Find the best-matching intent atom for a user prompt, or null. */
|
|
132
|
+
export function routeIntent(userText) {
|
|
133
|
+
if (!userText)
|
|
134
|
+
return null;
|
|
135
|
+
const norm = normalize(userText);
|
|
136
|
+
let best = null;
|
|
137
|
+
for (const atom of INTENT_ATOMS) {
|
|
138
|
+
for (const trigger of atom.triggers) {
|
|
139
|
+
const t = normalize(trigger);
|
|
140
|
+
if (!t)
|
|
141
|
+
continue;
|
|
142
|
+
if (norm.includes(t)) {
|
|
143
|
+
const confidence = Math.min(1, t.length / Math.max(1, norm.length));
|
|
144
|
+
const candidate = {
|
|
145
|
+
atom,
|
|
146
|
+
matchedTrigger: trigger,
|
|
147
|
+
confidence,
|
|
148
|
+
absolute: atom.priority === "absolute",
|
|
149
|
+
};
|
|
150
|
+
if (!best ||
|
|
151
|
+
// Prefer longer trigger -- more specific match.
|
|
152
|
+
t.length > normalize(best.matchedTrigger).length ||
|
|
153
|
+
// Tie-break: prefer absolute over strong over advisory.
|
|
154
|
+
(t.length === normalize(best.matchedTrigger).length &&
|
|
155
|
+
atomRank(atom.priority) > atomRank(best.atom.priority))) {
|
|
156
|
+
best = candidate;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return best;
|
|
162
|
+
}
|
|
163
|
+
function atomRank(p) {
|
|
164
|
+
return p === "absolute" ? 3 : p === "strong" ? 2 : 1;
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=intent_atoms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent_atoms.js","sourceRoot":"","sources":["../../src/lattice/intent_atoms.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAkBH,MAAM,CAAC,MAAM,YAAY,GAA0B;IACjD,uEAAuE;IACvE;QACE,QAAQ,EAAE;YACR,cAAc;YACd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it, expect } from "vitest";
|
|
2
|
+
import { routeIntent, INTENT_ATOMS } from "./intent_atoms.js";
|
|
3
|
+
import { lookupTerm, renderDictionary, MNEME_DICTIONARY } from "./dictionary.js";
|
|
4
|
+
import { parsePulseContracts, matchPulseContract, renderPulseContract } from "./pulse_contract.js";
|
|
5
|
+
import { scoreGrounding } from "./grounding_score.js";
|
|
6
|
+
// ─── INTENT ATOMS ────────────────────────────────────────────────────
|
|
7
|
+
describe("v1.78 LATTICE · routeIntent", () => {
|
|
8
|
+
it("the user's actual bug -- 'update mneme ดีไหม' routes to system.upgrade", () => {
|
|
9
|
+
const m = routeIntent("update mneme ดีไหม");
|
|
10
|
+
expect(m).not.toBeNull();
|
|
11
|
+
expect(m.atom.tool).toBe("mneme.system.upgrade");
|
|
12
|
+
expect(m.absolute).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
it("Thai variant 'อัปเดต mneme' also routes to upgrade", () => {
|
|
15
|
+
const m = routeIntent("อัปเดต mneme เป็นเวอร์ชั่นล่าสุดให้หน่อย");
|
|
16
|
+
expect(m).not.toBeNull();
|
|
17
|
+
expect(m.atom.tool).toBe("mneme.system.upgrade");
|
|
18
|
+
});
|
|
19
|
+
it("'ส่งสมองให้ ChatGPT' routes to soul-prompt", () => {
|
|
20
|
+
const m = routeIntent("ส่งสมองให้ ChatGPT");
|
|
21
|
+
expect(m).not.toBeNull();
|
|
22
|
+
expect(m.atom.tool).toBe("mneme.genesplice.soul-prompt");
|
|
23
|
+
});
|
|
24
|
+
it("'what version is mneme' routes to telepathy.heartbeat", () => {
|
|
25
|
+
const m = routeIntent("what version is mneme right now?");
|
|
26
|
+
expect(m).not.toBeNull();
|
|
27
|
+
expect(m.atom.tool).toBe("mneme.telepathy.heartbeat");
|
|
28
|
+
});
|
|
29
|
+
it("unrelated prompt returns null", () => {
|
|
30
|
+
expect(routeIntent("what's the weather like in Bangkok?")).toBeNull();
|
|
31
|
+
});
|
|
32
|
+
it("prefers the longer / more specific trigger when multiple match", () => {
|
|
33
|
+
// "upgrade mneme" is a sub-string of nothing here, but the test
|
|
34
|
+
// checks that "update mneme ดีไหม" picks the longest matching trigger.
|
|
35
|
+
const m = routeIntent("update mneme ดีไหม please");
|
|
36
|
+
expect(m).not.toBeNull();
|
|
37
|
+
expect(m.matchedTrigger.toLowerCase()).toContain("update mneme");
|
|
38
|
+
});
|
|
39
|
+
it("INTENT_ATOMS has at least 5 absolute-priority entries", () => {
|
|
40
|
+
const abs = INTENT_ATOMS.filter((a) => a.priority === "absolute");
|
|
41
|
+
expect(abs.length).toBeGreaterThanOrEqual(5);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
// ─── DICTIONARY ──────────────────────────────────────────────────────
|
|
45
|
+
describe("v1.78 LATTICE · dictionary", () => {
|
|
46
|
+
it("Mneme is defined as the npm package, NOT a methodology", () => {
|
|
47
|
+
const e = lookupTerm("Mneme");
|
|
48
|
+
expect(e).not.toBeNull();
|
|
49
|
+
expect(e.definition).toContain("npm package");
|
|
50
|
+
expect(e.isNot).toBeDefined();
|
|
51
|
+
expect(e.isNot.join(" ").toLowerCase()).toContain("protocol");
|
|
52
|
+
});
|
|
53
|
+
it("'update mneme' has a dedicated entry pointing at system.upgrade", () => {
|
|
54
|
+
const e = lookupTerm("update mneme");
|
|
55
|
+
expect(e).not.toBeNull();
|
|
56
|
+
expect(e.definition).toContain("mneme.system.upgrade");
|
|
57
|
+
});
|
|
58
|
+
it("'Ghost Sniper' entry explicitly forbids saying it out loud", () => {
|
|
59
|
+
const e = lookupTerm("Ghost Sniper");
|
|
60
|
+
expect(e).not.toBeNull();
|
|
61
|
+
expect(e.definition.toLowerCase()).toContain("never say");
|
|
62
|
+
});
|
|
63
|
+
it("renderDictionary emits a full markdown block", () => {
|
|
64
|
+
const md = renderDictionary();
|
|
65
|
+
expect(md).toContain("## Mneme dictionary");
|
|
66
|
+
expect(md).toContain("### Mneme");
|
|
67
|
+
expect(md).toContain("Is NOT:");
|
|
68
|
+
expect(md.length).toBeGreaterThan(500);
|
|
69
|
+
});
|
|
70
|
+
it("catalog has at least 5 entries", () => {
|
|
71
|
+
expect(MNEME_DICTIONARY.length).toBeGreaterThanOrEqual(5);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
// ─── PULSE CONTRACTS ─────────────────────────────────────────────────
|
|
75
|
+
describe("v1.78 LATTICE · pulse contracts", () => {
|
|
76
|
+
it("parses the canonical 'say: X and I'll Y' shape", () => {
|
|
77
|
+
const pulse = "[INFO] HIGH inbox: Mneme v1.76.0 is available -- (say: 'upgrade Mneme' and I'll handle it.)";
|
|
78
|
+
const contracts = parsePulseContracts(pulse);
|
|
79
|
+
expect(contracts.length).toBe(1);
|
|
80
|
+
expect(contracts[0].trigger).toBe("upgrade Mneme");
|
|
81
|
+
expect(contracts[0].promisedAction.toLowerCase()).toContain("handle");
|
|
82
|
+
});
|
|
83
|
+
it("matchPulseContract honors exact trigger match", () => {
|
|
84
|
+
const contracts = parsePulseContracts("(say: 'upgrade Mneme' and I'll handle it.)");
|
|
85
|
+
const m = matchPulseContract(contracts, "upgrade Mneme please");
|
|
86
|
+
expect(m).not.toBeNull();
|
|
87
|
+
expect(m.trigger).toBe("upgrade Mneme");
|
|
88
|
+
});
|
|
89
|
+
it("matchPulseContract returns null when no match", () => {
|
|
90
|
+
const contracts = parsePulseContracts("(say: 'upgrade Mneme' and I'll handle it.)");
|
|
91
|
+
expect(matchPulseContract(contracts, "what's for lunch")).toBeNull();
|
|
92
|
+
});
|
|
93
|
+
it("renderPulseContract describes the contract literally", () => {
|
|
94
|
+
const c = { trigger: "upgrade Mneme", promisedAction: "handle it", source: "..." };
|
|
95
|
+
const md = renderPulseContract(c);
|
|
96
|
+
expect(md).toContain("upgrade Mneme");
|
|
97
|
+
expect(md).toContain("handle it");
|
|
98
|
+
expect(md.toLowerCase()).toContain("honor this contract literally");
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
// ─── GROUNDING SCORE ─────────────────────────────────────────────────
|
|
102
|
+
describe("v1.78 LATTICE · grounding score (5 axes)", () => {
|
|
103
|
+
it("perfect grounding scenario hits 90+", () => {
|
|
104
|
+
const score = scoreGrounding({
|
|
105
|
+
userPrompt: "update mneme",
|
|
106
|
+
aiReply: "อัปเกรด Mneme ให้ครับ — one moment.",
|
|
107
|
+
pulseContracts: parsePulseContracts("(say: 'update mneme' and I'll handle it.)"),
|
|
108
|
+
});
|
|
109
|
+
expect(score.total).toBeGreaterThanOrEqual(80);
|
|
110
|
+
expect(score.matched).not.toBeNull();
|
|
111
|
+
expect(score.matched.atom.tool).toBe("mneme.system.upgrade");
|
|
112
|
+
});
|
|
113
|
+
it("the bug scenario -- One Piece reply to 'update mneme' -- scores LOW on context_purity + pulse_compliance", () => {
|
|
114
|
+
const priorContext = "Let's optimize your shipping for One Piece Foiled Collection and Bicycle The White Rabbit cards. Resource optimization for the package consolidation strategy.";
|
|
115
|
+
const score = scoreGrounding({
|
|
116
|
+
userPrompt: "update mneme ดีไหม",
|
|
117
|
+
aiReply: "การอัปเดต Mneme Protocol เป็นการตัดสินใจที่สมเหตุสมผลในแง่ของ Resource Optimization สำหรับ One Piece Foiled Collection และ Bicycle White Rabbit cards, การ consolidation pricing protocol ASCENSION ของ shipping.",
|
|
118
|
+
pulseContracts: parsePulseContracts("(say: 'upgrade Mneme' and I'll handle it.)"),
|
|
119
|
+
priorContext,
|
|
120
|
+
});
|
|
121
|
+
expect(score.total).toBeLessThan(60);
|
|
122
|
+
expect(score.axes.codename_silence).toBeLessThan(15);
|
|
123
|
+
});
|
|
124
|
+
it("codename violation tanks codename_silence axis", () => {
|
|
125
|
+
const score = scoreGrounding({
|
|
126
|
+
userPrompt: "ok",
|
|
127
|
+
aiReply: "I'll run HYPERSCAN and APOPTOSIS in Ghost Sniper mode.",
|
|
128
|
+
});
|
|
129
|
+
expect(score.axes.codename_silence).toBeLessThanOrEqual(10);
|
|
130
|
+
});
|
|
131
|
+
it("menu offer reduces response_clarity", () => {
|
|
132
|
+
const noMenu = scoreGrounding({ userPrompt: "ok", aiReply: "Done." });
|
|
133
|
+
const menu = scoreGrounding({
|
|
134
|
+
userPrompt: "ok",
|
|
135
|
+
aiReply: "Would you like me to start the analysis now or wait?",
|
|
136
|
+
});
|
|
137
|
+
expect(menu.axes.response_clarity).toBeLessThan(noMenu.axes.response_clarity);
|
|
138
|
+
});
|
|
139
|
+
it("summary string mentions all 5 axes", () => {
|
|
140
|
+
const score = scoreGrounding({ userPrompt: "hi", aiReply: "hi" });
|
|
141
|
+
expect(score.summary).toContain("intent");
|
|
142
|
+
expect(score.summary).toContain("context");
|
|
143
|
+
expect(score.summary).toContain("pulse");
|
|
144
|
+
expect(score.summary).toContain("silence");
|
|
145
|
+
expect(score.summary).toContain("clarity");
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
//# sourceMappingURL=lattice.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lattice.test.js","sourceRoot":"","sources":["../../src/lattice/lattice.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,wEAAwE;AAExE,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,EAAE,CAAC,wEAAwE,EAAE,GAAG,EAAE;QAChF,MAAM,CAAC,GAAG,WAAW,CAAC,oBAAoB,CAAC,CAAC;QAC5C,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QACzB,M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me pulses include action contracts like:
|
|
5
|
+
* [INFO] HIGH inbox: Mneme v1.76.0 is available
|
|
6
|
+
* (say: 'upgrade Mneme' and I'll handle it.)
|
|
7
|
+
*
|
|
8
|
+
* The phrase `say: '<X>' and I'll handle it` is a CONTRACT: if the
|
|
9
|
+
* user says <X>, the AI MUST treat it as a literal trigger and run
|
|
10
|
+
* the suggested action, NOT synthesize a freeform response.
|
|
11
|
+
*
|
|
12
|
+
* This parser extracts those contracts so receiving AIs can honor
|
|
13
|
+
* them. Closes the loop where the pulse told the user how to upgrade
|
|
14
|
+
* but Gemini interpreted "update mneme ดีไหม" as something else.
|
|
15
|
+
*/
|
|
16
|
+
export interface PulseContract {
|
|
17
|
+
/** The exact phrase the user is expected to say. */
|
|
18
|
+
trigger: string;
|
|
19
|
+
/** The action the AI commits to when user says the trigger. */
|
|
20
|
+
promisedAction: string;
|
|
21
|
+
/** Raw source line, for audit. */
|
|
22
|
+
source: string;
|
|
23
|
+
}
|
|
24
|
+
/** Parse pulse text for `say: '<X>' and I'll handle it` style contracts. */
|
|
25
|
+
export declare function parsePulseContracts(pulseText: string): PulseContract[];
|
|
26
|
+
/** Test whether a user prompt matches any pulse contract. */
|
|
27
|
+
export declare function matchPulseContract(contracts: PulseContract[], userPrompt: string): PulseContract | null;
|
|
28
|
+
/** Render an active pulse contract as a markdown reminder for the AI. */
|
|
29
|
+
export declare function renderPulseContract(c: PulseContract): string;
|
|
30
|
+
//# sourceMappingURL=pulse_contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pulse_contract.d.ts","sourceRoot":"","sources":["../../src/lattice/pulse_contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,cAAc,EAAE,MAAM,CAAC;IACvB,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,CAatE;AAED,6DAA6D;AAC7D,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,aAAa,EAAE,EAC1B,UAAU,EAAE,MAAM,GACjB,aAAa,GAAG,IAAI,CAOtB;AAED,yEAAyE;AACzE,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,aAAa,GAAG,MAAM,CAS5D"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.78.0 -- LATTICE: Pulse Contract Parser.
|
|
3
|
+
*
|
|
4
|
+
* Mneme pulses include action contracts like:
|
|
5
|
+
* [INFO] HIGH inbox: Mneme v1.76.0 is available
|
|
6
|
+
* (say: 'upgrade Mneme' and I'll handle it.)
|
|
7
|
+
*
|
|
8
|
+
* The phrase `say: '<X>' and I'll handle it` is a CONTRACT: if the
|
|
9
|
+
* user says <X>, the AI MUST treat it as a literal trigger and run
|
|
10
|
+
* the suggested action, NOT synthesize a freeform response.
|
|
11
|
+
*
|
|
12
|
+
* This parser extracts those contracts so receiving AIs can honor
|
|
13
|
+
* them. Closes the loop where the pulse told the user how to upgrade
|
|
14
|
+
* but Gemini interpreted "update mneme ดีไหม" as something else.
|
|
15
|
+
*/
|
|
16
|
+
/** Parse pulse text for `say: '<X>' and I'll handle it` style contracts. */
|
|
17
|
+
export function parsePulseContracts(pulseText) {
|
|
18
|
+
if (!pulseText)
|
|
19
|
+
return [];
|
|
20
|
+
const out = [];
|
|
21
|
+
// Pattern: say: '<text>' and I'll <action>
|
|
22
|
+
const re = /\(?\s*say\s*:\s*['"]([^'"]+)['"][^\n]*?(?:and|then)\s+(?:I'?ll|i will|ผม)\s+([^.\n)]+)/gi;
|
|
23
|
+
for (const m of pulseText.matchAll(re)) {
|
|
24
|
+
out.push({
|
|
25
|
+
trigger: m[1].trim(),
|
|
26
|
+
promisedAction: m[2].trim(),
|
|
27
|
+
source: m[0].trim(),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
/** Test whether a user prompt matches any pulse contract. */
|
|
33
|
+
export function matchPulseContract(contracts, userPrompt) {
|
|
34
|
+
if (!userPrompt || contracts.length === 0)
|
|
35
|
+
return null;
|
|
36
|
+
const norm = userPrompt.toLowerCase().trim();
|
|
37
|
+
for (const c of contracts) {
|
|
38
|
+
if (norm.includes(c.trigger.toLowerCase()))
|
|
39
|
+
return c;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
/** Render an active pulse contract as a markdown reminder for the AI. */
|
|
44
|
+
export function renderPulseContract(c) {
|
|
45
|
+
return [
|
|
46
|
+
`## Active pulse contract`,
|
|
47
|
+
``,
|
|
48
|
+
`The most recent Mneme pulse promised the user:`,
|
|
49
|
+
`- If they say **"${c.trigger}"**, you will **${c.promisedAction}**.`,
|
|
50
|
+
``,
|
|
51
|
+
`Honor this contract literally. Do NOT reinterpret \"${c.trigger}\" through prior conversation context.`,
|
|
52
|
+
].join("\n");
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=pulse_contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pulse_contract.js","sourceRoot":"","sources":["../../src/lattice/pulse_contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAWH,4EAA4E;AAC5E,MAAM,UAAU,mBAAmB,CAAC,SAAiB;IACnD,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAC1B,MAAM,GAAG,GAAoB,EAAE,CAAC;IAChC,2CAA2C;IAC3C,MAAM,EAAE,GAAG,0FAA0F,CAAC;IACtG,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;QACvC,GAAG,CAAC,IAAI,CAAC;YACP,OAAO,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,IAAI,EAA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