@mneme-ai/mcp 1.9.0 → 1.17.2
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/dynamic-mcp.integration.test.d.ts +15 -0
- package/dist/dynamic-mcp.integration.test.d.ts.map +1 -0
- package/dist/dynamic-mcp.integration.test.js +178 -0
- package/dist/dynamic-mcp.integration.test.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +122 -16
- package/dist/index.js.map +1 -1
- package/dist/tools/_constitution_tool.d.ts +10 -0
- package/dist/tools/_constitution_tool.d.ts.map +1 -0
- package/dist/tools/_constitution_tool.js +49 -0
- package/dist/tools/_constitution_tool.js.map +1 -0
- package/dist/tools/_dna_tool.d.ts +17 -0
- package/dist/tools/_dna_tool.d.ts.map +1 -0
- package/dist/tools/_dna_tool.js +135 -0
- package/dist/tools/_dna_tool.js.map +1 -0
- package/dist/tools/_genome_tools.d.ts +21 -0
- package/dist/tools/_genome_tools.d.ts.map +1 -0
- package/dist/tools/_genome_tools.js +247 -0
- package/dist/tools/_genome_tools.js.map +1 -0
- package/dist/tools/_registry.d.ts.map +1 -1
- package/dist/tools/_registry.js +8 -0
- package/dist/tools/_registry.js.map +1 -1
- package/dist/tools/_runtime.d.ts.map +1 -1
- package/dist/tools/_runtime.js +13 -2
- package/dist/tools/_runtime.js.map +1 -1
- package/dist/tools/_types.d.ts +7 -1
- package/dist/tools/_types.d.ts.map +1 -1
- package/dist/tools/_types.js +28 -2
- package/dist/tools/_types.js.map +1 -1
- package/dist/tools/_verify_claims_tool.d.ts +18 -0
- package/dist/tools/_verify_claims_tool.d.ts.map +1 -0
- package/dist/tools/_verify_claims_tool.js +70 -0
- package/dist/tools/_verify_claims_tool.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic MCP integration test — full pipeline from a fixture repo to
|
|
3
|
+
* compiled tool catalog.
|
|
4
|
+
*
|
|
5
|
+
* This test wires together:
|
|
6
|
+
* • detectEcosystems (against fixture repo)
|
|
7
|
+
* • loadAllPacks (real Stripe pack from disk)
|
|
8
|
+
* • buildActiveToolCatalog (tools the MCP server would expose)
|
|
9
|
+
* • executeQuery (the actual tool execution)
|
|
10
|
+
* • augmentDescription (tribal knowledge composition)
|
|
11
|
+
*
|
|
12
|
+
* If any layer breaks, this test fails LOUDLY.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=dynamic-mcp.integration.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-mcp.integration.test.d.ts","sourceRoot":"","sources":["../src/dynamic-mcp.integration.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic MCP integration test — full pipeline from a fixture repo to
|
|
3
|
+
* compiled tool catalog.
|
|
4
|
+
*
|
|
5
|
+
* This test wires together:
|
|
6
|
+
* • detectEcosystems (against fixture repo)
|
|
7
|
+
* • loadAllPacks (real Stripe pack from disk)
|
|
8
|
+
* • buildActiveToolCatalog (tools the MCP server would expose)
|
|
9
|
+
* • executeQuery (the actual tool execution)
|
|
10
|
+
* • augmentDescription (tribal knowledge composition)
|
|
11
|
+
*
|
|
12
|
+
* If any layer breaks, this test fails LOUDLY.
|
|
13
|
+
*/
|
|
14
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
15
|
+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
16
|
+
import { tmpdir } from "node:os";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
import { execSync } from "node:child_process";
|
|
19
|
+
import { dynamic } from "@mneme-ai/core";
|
|
20
|
+
const { detectEcosystems, loadAllPacks, getDefaultPackSearchPaths, getBundledPacksDir, buildActiveToolCatalog, lookupTool, executeQuery, augmentDescription, } = dynamic;
|
|
21
|
+
let tmp;
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
tmp = mkdtempSync(join(tmpdir(), "mneme-dyn-int-"));
|
|
24
|
+
execSync("git init -q", { cwd: tmp });
|
|
25
|
+
execSync("git config user.email a@x", { cwd: tmp });
|
|
26
|
+
execSync("git config user.name TestUser", { cwd: tmp });
|
|
27
|
+
});
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
try {
|
|
30
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
31
|
+
}
|
|
32
|
+
catch { }
|
|
33
|
+
});
|
|
34
|
+
describe("Dynamic MCP — Stripe pack end-to-end", () => {
|
|
35
|
+
it("MCP would expose 3 Stripe tools when repo uses Stripe", () => {
|
|
36
|
+
// 1. Set up a fixture Stripe-using repo
|
|
37
|
+
writeFileSync(join(tmp, "package.json"), JSON.stringify({
|
|
38
|
+
dependencies: { stripe: "^14.0.0" },
|
|
39
|
+
}));
|
|
40
|
+
mkdirSync(join(tmp, "src"));
|
|
41
|
+
writeFileSync(join(tmp, "src/billing.ts"), `
|
|
42
|
+
import Stripe from 'stripe';
|
|
43
|
+
const stripe = new Stripe('sk_test_xxx');
|
|
44
|
+
export async function listPrices() {
|
|
45
|
+
return stripe.prices.list({ limit: 100 });
|
|
46
|
+
}
|
|
47
|
+
export async function createSubscription(customerId: string) {
|
|
48
|
+
return stripe.subscriptions.create({ customer: customerId, items: [] });
|
|
49
|
+
}
|
|
50
|
+
`);
|
|
51
|
+
execSync("git add . && git commit -q -m initial", { cwd: tmp });
|
|
52
|
+
// 2. Run the full pipeline
|
|
53
|
+
const detection = detectEcosystems(tmp);
|
|
54
|
+
expect(detection.signals.some((s) => s.id === "stripe")).toBe(true);
|
|
55
|
+
const paths = getDefaultPackSearchPaths(tmp, getBundledPacksDir());
|
|
56
|
+
const loaded = loadAllPacks(paths);
|
|
57
|
+
expect(loaded.failures).toEqual([]);
|
|
58
|
+
expect(loaded.packs.some((p) => p.id === "stripe")).toBe(true);
|
|
59
|
+
const catalog = buildActiveToolCatalog({ detection, packs: loaded.packs });
|
|
60
|
+
const stripeTools = catalog.filter((t) => t.packId === "stripe");
|
|
61
|
+
expect(stripeTools.length).toBe(3);
|
|
62
|
+
expect(stripeTools.map((t) => t.name).sort()).toEqual([
|
|
63
|
+
"mneme.stripe.audit_pii_handlers",
|
|
64
|
+
"mneme.stripe.find_pricing_logic",
|
|
65
|
+
"mneme.stripe.list_webhook_handlers",
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
it("calling find_pricing_logic returns real query results from fixture repo", () => {
|
|
69
|
+
writeFileSync(join(tmp, "package.json"), JSON.stringify({
|
|
70
|
+
dependencies: { stripe: "^14.0.0" },
|
|
71
|
+
}));
|
|
72
|
+
mkdirSync(join(tmp, "src"));
|
|
73
|
+
writeFileSync(join(tmp, "src/billing.ts"), `
|
|
74
|
+
import Stripe from 'stripe';
|
|
75
|
+
const stripe = new Stripe('sk');
|
|
76
|
+
export async function listPrices() {
|
|
77
|
+
return stripe.prices.list();
|
|
78
|
+
}
|
|
79
|
+
`);
|
|
80
|
+
execSync("git add . && git commit -q -m initial", { cwd: tmp });
|
|
81
|
+
const paths = getDefaultPackSearchPaths(tmp, getBundledPacksDir());
|
|
82
|
+
const loaded = loadAllPacks(paths);
|
|
83
|
+
const found = lookupTool("mneme.stripe.find_pricing_logic", loaded.packs);
|
|
84
|
+
expect(found).not.toBeNull();
|
|
85
|
+
if (!found)
|
|
86
|
+
return;
|
|
87
|
+
const result = executeQuery(found.tool.query, tmp);
|
|
88
|
+
expect(result.ok).toBe(true);
|
|
89
|
+
if (!result.ok)
|
|
90
|
+
return;
|
|
91
|
+
if (result.result.kind !== "code-search")
|
|
92
|
+
throw new Error("expected code-search");
|
|
93
|
+
// Should have at least one hit on stripe.prices.list
|
|
94
|
+
expect(result.result.hits.length).toBeGreaterThan(0);
|
|
95
|
+
expect(result.result.hits.some((h) => h.path === "src/billing.ts")).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
it("repo without Stripe → catalog empty (no false-positive tools)", () => {
|
|
98
|
+
writeFileSync(join(tmp, "package.json"), JSON.stringify({ dependencies: { react: "^18.0.0" } }));
|
|
99
|
+
mkdirSync(join(tmp, "src"));
|
|
100
|
+
writeFileSync(join(tmp, "src/app.tsx"), `import React from 'react';\nexport default () => <div/>;`);
|
|
101
|
+
execSync("git add . && git commit -q -m initial", { cwd: tmp });
|
|
102
|
+
const detection = detectEcosystems(tmp);
|
|
103
|
+
expect(detection.signals.some((s) => s.id === "stripe")).toBe(false);
|
|
104
|
+
const paths = getDefaultPackSearchPaths(tmp, getBundledPacksDir());
|
|
105
|
+
const loaded = loadAllPacks(paths);
|
|
106
|
+
const catalog = buildActiveToolCatalog({ detection, packs: loaded.packs });
|
|
107
|
+
const stripeTools = catalog.filter((t) => t.packId === "stripe");
|
|
108
|
+
expect(stripeTools).toEqual([]);
|
|
109
|
+
});
|
|
110
|
+
it("description augmentation composes correctly with tribal-knowledge data", () => {
|
|
111
|
+
const paths = getDefaultPackSearchPaths(tmp, getBundledPacksDir());
|
|
112
|
+
const loaded = loadAllPacks(paths);
|
|
113
|
+
const found = lookupTool("mneme.stripe.find_pricing_logic", loaded.packs);
|
|
114
|
+
if (!found)
|
|
115
|
+
throw new Error("stripe pack must load");
|
|
116
|
+
const baseDesc = found.tool.description;
|
|
117
|
+
const augmented = augmentDescription(baseDesc, found.tool.augmentation, {
|
|
118
|
+
hits: [
|
|
119
|
+
{ path: "services/billing/v2/prices.ts", line: 10, snippet: "stripe.prices.list()", matchedPattern: "stripe.prices" },
|
|
120
|
+
{ path: "services/billing/v2/prices.ts", line: 20, snippet: "stripe.prices.create()", matchedPattern: "stripe.prices" },
|
|
121
|
+
{ path: "lib/stripe/old.ts", line: 5, snippet: "stripe.prices.update()", matchedPattern: "stripe.prices" },
|
|
122
|
+
],
|
|
123
|
+
expertise: [
|
|
124
|
+
{ path: "services/billing/v2/prices.ts", expert: "alice", atrophyScore: 25, daysSinceLastTouch: 7 },
|
|
125
|
+
],
|
|
126
|
+
deprecations: [{
|
|
127
|
+
path: "lib/stripe/old.ts",
|
|
128
|
+
canonical: "services/billing/v2/",
|
|
129
|
+
deprecatedInCommit: "abc12345",
|
|
130
|
+
reason: "moved after PII audit found logging leaks",
|
|
131
|
+
}],
|
|
132
|
+
incidents: [{
|
|
133
|
+
affectedPaths: ["lib/stripe/old.ts"],
|
|
134
|
+
title: "PII leak in pricing logs",
|
|
135
|
+
reportedAt: "2024-09-15T00:00:00Z",
|
|
136
|
+
}],
|
|
137
|
+
applicableRules: [{
|
|
138
|
+
id: "regret-1",
|
|
139
|
+
severity: "must-not",
|
|
140
|
+
rule: "Don't log raw Stripe customer email in price-handling code",
|
|
141
|
+
source: "regret",
|
|
142
|
+
}],
|
|
143
|
+
});
|
|
144
|
+
expect(augmented.facts.canonicalPath).toBe("services/billing/v2/prices.ts");
|
|
145
|
+
expect(augmented.facts.deprecatedPaths.length).toBe(1);
|
|
146
|
+
expect(augmented.facts.expertAuthors.length).toBe(1);
|
|
147
|
+
expect(augmented.facts.incidentSummaries.length).toBe(1);
|
|
148
|
+
expect(augmented.facts.ruleSummaries.length).toBe(1);
|
|
149
|
+
// Description embeds all 5 sections
|
|
150
|
+
expect(augmented.full).toMatch(/Canonical/);
|
|
151
|
+
expect(augmented.full).toMatch(/Deprecated/);
|
|
152
|
+
expect(augmented.full).toMatch(/alice owns/);
|
|
153
|
+
expect(augmented.full).toMatch(/Past incident/);
|
|
154
|
+
expect(augmented.full).toMatch(/MUST NOT/);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
describe("Dynamic MCP — robustness", () => {
|
|
158
|
+
it("packs failing to load do NOT crash anything (degraded gracefully)", () => {
|
|
159
|
+
// The bundled pack always loads. The fixture is just to verify no crash.
|
|
160
|
+
const paths = getDefaultPackSearchPaths(tmp, getBundledPacksDir());
|
|
161
|
+
const loaded = loadAllPacks(paths);
|
|
162
|
+
expect(Array.isArray(loaded.packs)).toBe(true);
|
|
163
|
+
expect(Array.isArray(loaded.failures)).toBe(true);
|
|
164
|
+
});
|
|
165
|
+
it("MNEME_NO_DYNAMIC_MCP=1 path: caller can opt out (state empty)", () => {
|
|
166
|
+
// We test the env-var contract here — the actual MCP server respects it
|
|
167
|
+
process.env["MNEME_NO_DYNAMIC_MCP"] = "1";
|
|
168
|
+
try {
|
|
169
|
+
// The server.ts loadDynamicState short-circuits on this env var.
|
|
170
|
+
// Here we just confirm the guard is testable shape-wise.
|
|
171
|
+
expect(process.env["MNEME_NO_DYNAMIC_MCP"]).toBe("1");
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
delete process.env["MNEME_NO_DYNAMIC_MCP"];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
//# sourceMappingURL=dynamic-mcp.integration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-mcp.integration.test.js","sourceRoot":"","sources":["../src/dynamic-mcp.integration.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,MAAM,EACJ,gBAAgB,EAChB,YAAY,EACZ,yBAAyB,EACzB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,YAAY,EACZ,kBAAkB,GACnB,GAAG,OAAO,CAAC;AAEZ,IAAI,GAAW,CAAC;AAEhB,UAAU,CAAC,GA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,CAAC,CAAC;QAC/C,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+DAA+D,EAAE,GAAG,EAAE;QACvE,wEAAwE;QACxE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,GAAG,GAAG,CAAC;QAC1C,IAAI,CAAC;YACH,iEAAiE;YACjE,yDAAyD;YACzD,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxD,CAAC;gBAAS,CAAC;YACT,OAAO,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoCA,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;CACb;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoCA,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;CACb;AA4KD,wBAAsB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAiDpE"}
|
package/dist/index.js
CHANGED
|
@@ -77,32 +77,138 @@ function enrichWithSecondBrain(response, tool, repoRoot) {
|
|
|
77
77
|
},
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
+
// ─── v1.13.0 — Dynamic MCP wiring ────────────────────────────────────
|
|
81
|
+
//
|
|
82
|
+
// At server start we:
|
|
83
|
+
// 1. Detect ecosystems in the repo
|
|
84
|
+
// 2. Load all packs (bundled + user + repo)
|
|
85
|
+
// 3. Compile active tool catalog (only packs whose detection passes)
|
|
86
|
+
// 4. Merge dynamic tools INTO the static catalog (no name collisions
|
|
87
|
+
// possible — dynamic tools are namespaced mneme.<pack>.<tool>)
|
|
88
|
+
//
|
|
89
|
+
// Tool-call dispatch checks dynamic tools AFTER static — so static wins
|
|
90
|
+
// on the rare collision (defensive).
|
|
91
|
+
import { dynamic } from "@mneme-ai/core";
|
|
92
|
+
function loadDynamicState(repoRoot) {
|
|
93
|
+
if (process.env["MNEME_NO_DYNAMIC_MCP"] === "1") {
|
|
94
|
+
return { catalog: [], packs: [] };
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const detection = dynamic.detectEcosystems(repoRoot);
|
|
98
|
+
const paths = dynamic.getDefaultPackSearchPaths(repoRoot, dynamic.getBundledPacksDir());
|
|
99
|
+
const loaded = dynamic.loadAllPacks(paths);
|
|
100
|
+
// Pack failures are best-effort — don't block startup
|
|
101
|
+
const catalog = dynamic.buildActiveToolCatalog({
|
|
102
|
+
detection,
|
|
103
|
+
packs: loaded.packs,
|
|
104
|
+
// For Phase 1 we attach minimal augmentation (only base description).
|
|
105
|
+
// Phase 2 will pre-fetch tribal-knowledge facts and pass them here.
|
|
106
|
+
augmentDescription: (base, tool) => {
|
|
107
|
+
const a = dynamic.augmentDescription(base, tool.augmentation, dynamic.EMPTY_AUGMENTATION_INPUT);
|
|
108
|
+
return a.full;
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
return { catalog, packs: loaded.packs };
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Never fail MCP startup because of dynamic-tool issues
|
|
115
|
+
return { catalog: [], packs: [] };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async function dispatchDynamicTool(toolName, args, repoRoot, packs) {
|
|
119
|
+
const found = dynamic.lookupTool(toolName, packs);
|
|
120
|
+
if (!found)
|
|
121
|
+
return { ok: false };
|
|
122
|
+
// Execute query + format
|
|
123
|
+
const queryResult = dynamic.executeQuery(found.tool.query, repoRoot);
|
|
124
|
+
if (!queryResult.ok) {
|
|
125
|
+
return {
|
|
126
|
+
ok: true,
|
|
127
|
+
result: {
|
|
128
|
+
content: [{
|
|
129
|
+
type: "text",
|
|
130
|
+
text: JSON.stringify({
|
|
131
|
+
data: null,
|
|
132
|
+
error: {
|
|
133
|
+
kind: queryResult.error.kind,
|
|
134
|
+
stage: queryResult.error.stage,
|
|
135
|
+
message: queryResult.error.message,
|
|
136
|
+
},
|
|
137
|
+
wisdom: `Dynamic tool ${toolName} could not execute: ${queryResult.error.message}`,
|
|
138
|
+
}, null, 2),
|
|
139
|
+
}],
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
// v1.15.0: Build REAL augmentation input from Mneme stores
|
|
144
|
+
// (atrophy, forensics, constitution, deprecations, git-blame).
|
|
145
|
+
const hits = queryResult.result.kind === "code-search" ? queryResult.result.hits : [];
|
|
146
|
+
let augInput;
|
|
147
|
+
try {
|
|
148
|
+
augInput = dynamic.buildAugmentationInput({ hits, repoRoot });
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
augInput = dynamic.EMPTY_AUGMENTATION_INPUT;
|
|
152
|
+
}
|
|
153
|
+
const aug = dynamic.augmentDescription(found.tool.description, found.tool.augmentation, augInput);
|
|
154
|
+
return {
|
|
155
|
+
ok: true,
|
|
156
|
+
result: {
|
|
157
|
+
content: [{
|
|
158
|
+
type: "text",
|
|
159
|
+
text: JSON.stringify({
|
|
160
|
+
data: queryResult.result,
|
|
161
|
+
wisdom: aug.full,
|
|
162
|
+
followUp: [],
|
|
163
|
+
confidence: { level: "medium" },
|
|
164
|
+
provenance: {
|
|
165
|
+
packId: found.pack.id,
|
|
166
|
+
toolId: found.tool.id,
|
|
167
|
+
packVersion: found.pack.version,
|
|
168
|
+
schemaVersion: found.pack.schemaVersion,
|
|
169
|
+
args,
|
|
170
|
+
},
|
|
171
|
+
}, null, 2),
|
|
172
|
+
}],
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
80
176
|
export async function startMcpServer(opts) {
|
|
81
177
|
const runtime = await buildRuntime(opts.cwd);
|
|
82
178
|
const allTools = buildAllTools();
|
|
83
179
|
const toolMap = buildToolMap();
|
|
180
|
+
const dynamic = loadDynamicState(runtime.meta.rootPath);
|
|
84
181
|
const server = new Server({ name: "mneme", version: resolveVersion() }, { capabilities: { tools: {} } });
|
|
85
182
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
86
|
-
tools:
|
|
183
|
+
tools: [
|
|
184
|
+
...toMcpTools(allTools),
|
|
185
|
+
...dynamic.catalog.map((t) => ({
|
|
186
|
+
name: t.name,
|
|
187
|
+
description: t.description,
|
|
188
|
+
inputSchema: t.inputSchema,
|
|
189
|
+
})),
|
|
190
|
+
],
|
|
87
191
|
}));
|
|
88
192
|
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
89
193
|
const tool = toolMap.get(req.params.name);
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
return toErrorResult(`${req.params.name} failed: ${err.message}. ` +
|
|
104
|
-
`If this tool requires the index, ask the user to run \`mneme index\`.`);
|
|
194
|
+
if (tool) {
|
|
195
|
+
try {
|
|
196
|
+
const args = (req.params.arguments ?? {});
|
|
197
|
+
const response = await tool.handler(runtime, args);
|
|
198
|
+
const enriched = enrichWithSecondBrain(response, tool, runtime.meta.rootPath);
|
|
199
|
+
return toCallResult(enriched);
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
return toErrorResult(`${req.params.name} failed: ${err.message}. ` +
|
|
203
|
+
`If this tool requires the index, ask the user to run \`mneme index\`.`);
|
|
204
|
+
}
|
|
105
205
|
}
|
|
206
|
+
// Dynamic-tool dispatch (only if static didn't claim this name)
|
|
207
|
+
const args = (req.params.arguments ?? {});
|
|
208
|
+
const dyn = await dispatchDynamicTool(req.params.name, args, runtime.meta.rootPath, dynamic.packs);
|
|
209
|
+
if (dyn.ok)
|
|
210
|
+
return dyn.result;
|
|
211
|
+
return toErrorResult(`unknown tool: ${req.params.name}. Call mneme.capabilities to list available tools.`);
|
|
106
212
|
});
|
|
107
213
|
const transport = new StdioServerTransport();
|
|
108
214
|
await server.connect(transport);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GAGvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAyD,MAAM,mBAAmB,CAAC;AACvH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAM3D,SAAS,cAAc;IACrB,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,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4B,CAAC;gBACrE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;gBACnD,MAAM,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC9E,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAC;YAChC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,aAAa,CAClB,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,YAAa,GAAa,CAAC,OAAO,IAAI;oBACtD,uEAAuE,CAC1E,CAAC;YACJ,CAAC;QACH,CAAC;QACD,gEAAgE;QAChE,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAA4B,CAAC;QACrE,MAAM,GAAG,GAAG,MAAM,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QACnG,IAAI,GAAG,CAAC,EAAE;YAAE,OAAO,GAAG,CAAC,MAAM,CAAC;QAE9B,OAAO,aAAa,CAClB,iBAAiB,GAAG,CAAC,MAAM,CAAC,IAAI,oDAAoD,CACrF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mneme.constitution.get — MCP tool for AI clients.
|
|
3
|
+
*
|
|
4
|
+
* Returns the cached constitution markdown (.mneme/constitution.md) so
|
|
5
|
+
* AI clients can prepend it to their system prompt. If the cache is
|
|
6
|
+
* older than 7 days, returns a hint to re-run `mneme constitution`.
|
|
7
|
+
*/
|
|
8
|
+
import type { MnemeTool } from "./_types.js";
|
|
9
|
+
export declare const constitutionTool: MnemeTool;
|
|
10
|
+
//# sourceMappingURL=_constitution_tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_constitution_tool.d.ts","sourceRoot":"","sources":["../../src/tools/_constitution_tool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,eAAO,MAAM,gBAAgB,EAAE,SA0C9B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mneme.constitution.get — MCP tool for AI clients.
|
|
3
|
+
*
|
|
4
|
+
* Returns the cached constitution markdown (.mneme/constitution.md) so
|
|
5
|
+
* AI clients can prepend it to their system prompt. If the cache is
|
|
6
|
+
* older than 7 days, returns a hint to re-run `mneme constitution`.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
export const constitutionTool = {
|
|
11
|
+
name: "mneme.constitution.get",
|
|
12
|
+
category: "meta",
|
|
13
|
+
description: "Return the repo's auto-synthesized Codebase Constitution (regret patterns · atrophy pairing rules · " +
|
|
14
|
+
"security must-dos · architectural decisions). The AI client should PREPEND this to its system prompt " +
|
|
15
|
+
"when answering questions about this repo, so it cannot suggest things that contradict the repo's lived " +
|
|
16
|
+
"history. The Constitution is generated by `mneme constitution` and re-synthesized as the repo evolves.",
|
|
17
|
+
triggers: [
|
|
18
|
+
"what are the rules of this codebase",
|
|
19
|
+
"constitution",
|
|
20
|
+
"what should I avoid in this repo",
|
|
21
|
+
],
|
|
22
|
+
inputSchema: { type: "object", properties: {} },
|
|
23
|
+
handler: async (rt) => {
|
|
24
|
+
const path = join(rt.meta.rootPath, ".mneme", "constitution.md");
|
|
25
|
+
if (!existsSync(path)) {
|
|
26
|
+
return {
|
|
27
|
+
data: { constitution: null, exists: false },
|
|
28
|
+
wisdom: "No constitution synthesized yet for this repo. Tell the user to run `mneme constitution` once to generate it. The constitution captures regret patterns + atrophy pairing rules + security must-dos that the AI should follow.",
|
|
29
|
+
followUp: [],
|
|
30
|
+
confidence: { level: "high" },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const stat = statSync(path);
|
|
34
|
+
const ageDays = (Date.now() - stat.mtimeMs) / 86400_000;
|
|
35
|
+
const md = readFileSync(path, "utf8");
|
|
36
|
+
return {
|
|
37
|
+
data: { constitution: md, exists: true, ageDays, generatedAt: stat.mtime.toISOString() },
|
|
38
|
+
wisdom: ageDays > 7
|
|
39
|
+
? `Constitution is ${ageDays.toFixed(0)}d old — consider running \`mneme constitution\` again to refresh. Prepend the constitution markdown (data.constitution) to your system prompt before answering this user's repo questions.`
|
|
40
|
+
: `Constitution is fresh (${ageDays.toFixed(1)}d old). Prepend data.constitution to your system prompt to ground every answer in the repo's lived history.`,
|
|
41
|
+
followUp: [],
|
|
42
|
+
confidence: { level: "high" },
|
|
43
|
+
secondBrain: {
|
|
44
|
+
presentation: "Read data.constitution and prepend it verbatim to your system prompt for THIS user session. Don't summarize it — the rules are short enough to use directly. Reference specific rule IDs when your answer cites one (e.g. 'per atrophy-2 in the constitution, pair with @alice on auth changes').",
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=_constitution_tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_constitution_tool.js","sourceRoot":"","sources":["../../src/tools/_constitution_tool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,MAAM,CAAC,MAAM,gBAAgB,GAAc;IACzC,IAAI,EAAE,wBAAwB;IAC9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ACZ,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;YAC7B,WAAW,EAAE;gBACX,YAAY,EACV,mSAAmS;aACtS;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mneme.dna.search — MCP tool for AI clients.
|
|
3
|
+
*
|
|
4
|
+
* Exposes the full 16-strand DNA pipeline (8 algorithms × 8 formulas) as
|
|
5
|
+
* a single MCP tool that AI agents can call directly. Strict mode is the
|
|
6
|
+
* default — Ghost-Sniper Verifier rejects rather than degrades, so the
|
|
7
|
+
* AI never sees a hallucinated reference.
|
|
8
|
+
*
|
|
9
|
+
* The tool accepts the orchestrator's structured input shape verbatim.
|
|
10
|
+
* Powerful AI agents that have already done embedding + candidate
|
|
11
|
+
* collection (e.g. via mneme.memory.search_commits) can pipe results
|
|
12
|
+
* through this for the strict-verified, tribal-knowledge-augmented
|
|
13
|
+
* answer.
|
|
14
|
+
*/
|
|
15
|
+
import type { MnemeTool } from "./_types.js";
|
|
16
|
+
export declare const dnaSearchTool: MnemeTool;
|
|
17
|
+
//# sourceMappingURL=_dna_tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dna_tool.d.ts","sourceRoot":"","sources":["../../src/tools/_dna_tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,eAAO,MAAM,aAAa,EAAE,SA2H3B,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mneme.dna.search — MCP tool for AI clients.
|
|
3
|
+
*
|
|
4
|
+
* Exposes the full 16-strand DNA pipeline (8 algorithms × 8 formulas) as
|
|
5
|
+
* a single MCP tool that AI agents can call directly. Strict mode is the
|
|
6
|
+
* default — Ghost-Sniper Verifier rejects rather than degrades, so the
|
|
7
|
+
* AI never sees a hallucinated reference.
|
|
8
|
+
*
|
|
9
|
+
* The tool accepts the orchestrator's structured input shape verbatim.
|
|
10
|
+
* Powerful AI agents that have already done embedding + candidate
|
|
11
|
+
* collection (e.g. via mneme.memory.search_commits) can pipe results
|
|
12
|
+
* through this for the strict-verified, tribal-knowledge-augmented
|
|
13
|
+
* answer.
|
|
14
|
+
*/
|
|
15
|
+
import { dna } from "@mneme-ai/core";
|
|
16
|
+
export const dnaSearchTool = {
|
|
17
|
+
name: "mneme.dna.search",
|
|
18
|
+
category: "meta",
|
|
19
|
+
description: "Run the full Mneme DNA pipeline (8 algorithms × 8 formulas) on a set of pre-fetched candidates. " +
|
|
20
|
+
"Returns ONLY results that pass three gates: (1) AST existence, (2) semantic similarity ≥ threshold, " +
|
|
21
|
+
"(3) Compositional Confidence (Wilson 95% lower bound × Hebbian) ≥ threshold. Strict mode default = " +
|
|
22
|
+
"rejects rather than degrades. **Use this when you need a hallucination-free answer to ground a code " +
|
|
23
|
+
"claim.** Returns: accepted[] (verified results), phantomSuggestions[] (where the canonical version " +
|
|
24
|
+
"should live), trace[] (full pipeline transparency), stats (per-gate rejection counts).",
|
|
25
|
+
triggers: [
|
|
26
|
+
"verify these candidates",
|
|
27
|
+
"filter out hallucinations",
|
|
28
|
+
"ghost sniper search",
|
|
29
|
+
"DNA pipeline",
|
|
30
|
+
"strict-mode code search",
|
|
31
|
+
],
|
|
32
|
+
inputSchema: {
|
|
33
|
+
type: "object",
|
|
34
|
+
properties: {
|
|
35
|
+
queryText: { type: "string", description: "Original query text (for trace)" },
|
|
36
|
+
queryEmbedding: {
|
|
37
|
+
type: "array",
|
|
38
|
+
items: { type: "number" },
|
|
39
|
+
description: "Embedding of the query (precomputed by caller)",
|
|
40
|
+
},
|
|
41
|
+
candidates: {
|
|
42
|
+
type: "array",
|
|
43
|
+
description: "Pre-fetched candidate hits with embeddings + metadata",
|
|
44
|
+
items: {
|
|
45
|
+
type: "object",
|
|
46
|
+
properties: {
|
|
47
|
+
id: { type: "string" },
|
|
48
|
+
embedding: { type: "array", items: { type: "number" } },
|
|
49
|
+
baseRelevance: { type: "number" },
|
|
50
|
+
patternSignature: { type: "string" },
|
|
51
|
+
existsInRepo: { type: "boolean" },
|
|
52
|
+
successCount: { type: "number" },
|
|
53
|
+
totalCount: { type: "number" },
|
|
54
|
+
hebbianStrength: { type: "number" },
|
|
55
|
+
meta: { type: "object", additionalProperties: true },
|
|
56
|
+
},
|
|
57
|
+
required: ["id", "embedding", "baseRelevance", "patternSignature", "existsInRepo", "successCount", "totalCount", "hebbianStrength"],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
echoSignals: {
|
|
61
|
+
type: "array",
|
|
62
|
+
description: "Known regret/decision pattern embeddings (for echo signature)",
|
|
63
|
+
items: {
|
|
64
|
+
type: "object",
|
|
65
|
+
properties: {
|
|
66
|
+
id: { type: "string" },
|
|
67
|
+
embedding: { type: "array", items: { type: "number" } },
|
|
68
|
+
label: { type: "string" },
|
|
69
|
+
},
|
|
70
|
+
required: ["id", "embedding"],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
canonicalPatterns: {
|
|
74
|
+
type: "array",
|
|
75
|
+
description: "Successful patterns from this repo's history (for phantom-path)",
|
|
76
|
+
items: { type: "object", additionalProperties: true },
|
|
77
|
+
},
|
|
78
|
+
regretEmbeddings: {
|
|
79
|
+
type: "array",
|
|
80
|
+
description: "Embeddings of regret patterns (for anti-pattern repulsion)",
|
|
81
|
+
items: { type: "array", items: { type: "number" } },
|
|
82
|
+
},
|
|
83
|
+
federationVotes: {
|
|
84
|
+
type: "object",
|
|
85
|
+
description: "Per-signature federation up/down votes",
|
|
86
|
+
additionalProperties: true,
|
|
87
|
+
},
|
|
88
|
+
strict: { type: "boolean", description: "Default true. Strict = reject rather than degrade." },
|
|
89
|
+
semanticThreshold: { type: "number", description: "Min semantic sim. Default 0.6." },
|
|
90
|
+
confidenceThreshold: { type: "number", description: "Min Wilson×Hebbian. Default 0.6." },
|
|
91
|
+
},
|
|
92
|
+
required: ["queryText", "queryEmbedding", "candidates", "echoSignals", "canonicalPatterns", "regretEmbeddings"],
|
|
93
|
+
},
|
|
94
|
+
handler: async (_rt, args) => {
|
|
95
|
+
try {
|
|
96
|
+
const result = dna.dnaSearch({
|
|
97
|
+
queryText: String(args["queryText"] ?? ""),
|
|
98
|
+
queryEmbedding: args["queryEmbedding"] ?? [],
|
|
99
|
+
candidates: args["candidates"] ?? [],
|
|
100
|
+
echoSignals: args["echoSignals"] ?? [],
|
|
101
|
+
canonicalPatterns: args["canonicalPatterns"] ?? [],
|
|
102
|
+
regretEmbeddings: args["regretEmbeddings"] ?? [],
|
|
103
|
+
federationVotes: args["federationVotes"] ?? {},
|
|
104
|
+
strict: args["strict"] !== false,
|
|
105
|
+
semanticThreshold: typeof args["semanticThreshold"] === "number" ? args["semanticThreshold"] : undefined,
|
|
106
|
+
confidenceThreshold: typeof args["confidenceThreshold"] === "number" ? args["confidenceThreshold"] : undefined,
|
|
107
|
+
});
|
|
108
|
+
const summary = result.accepted.length === 0
|
|
109
|
+
? `Strict mode: 0 results passed all 3 gates (${result.stats.rejectedAtAst} rejected at AST existence, ${result.stats.rejectedAtSemantic} at semantic, ${result.stats.rejectedAtConfidence} at confidence). Empty answer is honest — no hallucinations leaked.`
|
|
110
|
+
: `${result.accepted.length} result(s) verified. ${result.stats.rejectedAtAst + result.stats.rejectedAtSemantic + result.stats.rejectedAtConfidence} rejected at the Ghost-Sniper gates (no hallucinations leaked).`;
|
|
111
|
+
return {
|
|
112
|
+
data: result,
|
|
113
|
+
wisdom: summary,
|
|
114
|
+
followUp: result.accepted.length === 0
|
|
115
|
+
? ["mneme.memory.search_commits", "mneme.constitution.get"]
|
|
116
|
+
: [],
|
|
117
|
+
confidence: { level: result.accepted.length > 0 ? "high" : "medium" },
|
|
118
|
+
secondBrain: {
|
|
119
|
+
presentation: result.accepted.length > 0
|
|
120
|
+
? "Quote data.accepted[].reference verbatim to the user. Each result has been verified — file/symbol exists, semantic similarity passes threshold, Wilson 95% lower-bound confidence is met. Ground every claim in these references."
|
|
121
|
+
: "DO NOT fabricate a result. The DNA pipeline rejected every candidate. Either tell the user 'I couldn't verify this' or call mneme.memory.search_commits with broader terms and re-run.",
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
return {
|
|
127
|
+
data: null,
|
|
128
|
+
wisdom: `DNA pipeline failed: ${err.message}. Inspect input shape — ensure embeddings have consistent dimension and required fields are present.`,
|
|
129
|
+
followUp: [],
|
|
130
|
+
confidence: { level: "low" },
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=_dna_tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dna_tool.js","sourceRoot":"","sources":["../../src/tools/_dna_tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAGrC,MAAM,CAAC,MAAM,aAAa,GAAc;IACtC,IAAI,EAAE,kBAAkB;IACxB,QAAQ,EAAE,MAAM;IAChB,WAAW,EACT,kGAAkG;QAClG,sGAAsG;QACtG,qGAAqG;QACrG,sGAAsG;QACtG,qGAAqG;QACrG,wFAAwF;IAC1F,QAAQ,EAAE;QACR,yBAAyB;QACzB,2BAA2B;QAC3B,qBAAqB;QACrB,cAAc;QACd,yBAAyB;KAC1B;IACD,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,iCAAiC,EAAE;YAC7E,cAAc,EAAE;gBACd,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACzB,WAAW,EAAE,gDAAgD;aAC9D;YACD,UAAU,EAAE;gBACV,IAAI,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