codemap-ai 3.2.0 → 3.5.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/README.md +28 -1
- package/dist/{chunk-VB74K47A.js → chunk-BRVRY5KT.js} +62 -1
- package/dist/chunk-BRVRY5KT.js.map +1 -0
- package/dist/{chunk-LXZ73T7X.js → chunk-EEMILSZ4.js} +58 -3
- package/dist/chunk-EEMILSZ4.js.map +1 -0
- package/dist/cli.js +1828 -44
- package/dist/cli.js.map +1 -1
- package/dist/{flow-server-UQEOUP2C.js → flow-server-FMPWJSLK.js} +3 -3
- package/dist/{flow-server-UQEOUP2C.js.map → flow-server-FMPWJSLK.js.map} +1 -1
- package/dist/index.js +1052 -21
- package/dist/index.js.map +1 -1
- package/dist/mcp-server.js +2 -2
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-LXZ73T7X.js.map +0 -1
- package/dist/chunk-VB74K47A.js.map +0 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
FlowStorage
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-BRVRY5KT.js";
|
|
6
6
|
|
|
7
7
|
// src/mcp/flow-server.ts
|
|
8
8
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -29,7 +29,7 @@ function getStorage() {
|
|
|
29
29
|
var server = new Server(
|
|
30
30
|
{
|
|
31
31
|
name: "codemap-flow",
|
|
32
|
-
version: "3.
|
|
32
|
+
version: "3.5.0"
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
capabilities: {
|
|
@@ -243,4 +243,4 @@ server.connect(transport).catch((error) => {
|
|
|
243
243
|
console.error("Failed to start MCP server:", error);
|
|
244
244
|
process.exit(1);
|
|
245
245
|
});
|
|
246
|
-
//# sourceMappingURL=flow-server-
|
|
246
|
+
//# sourceMappingURL=flow-server-FMPWJSLK.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mcp/flow-server.ts"],"sourcesContent":["/**\n * MCP Server for CodeMap Flow Edition\n * Provides 3 focused tools: impact analysis, flow tracing, and caller lookup\n */\n\nimport { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport {\n CallToolRequestSchema,\n ListToolsRequestSchema,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { FlowStorage } from \"../flow/storage.js\";\nimport { resolve } from \"path\";\nimport { existsSync } from \"fs\";\n\n// Get config from environment\nconst DB_PATH = process.env.CODEMAP_DB_PATH || \".codemap/graph.db\";\nconst PROJECT_ROOT = process.env.CODEMAP_PROJECT_ROOT || process.cwd();\n\nlet storage: FlowStorage | null = null;\n\nfunction getStorage(): FlowStorage {\n if (!storage) {\n const dbPath = resolve(PROJECT_ROOT, DB_PATH);\n if (!existsSync(dbPath)) {\n throw new Error(`CodeMap database not found at ${dbPath}. Run 'codemap index' first.`);\n }\n storage = new FlowStorage(dbPath);\n }\n return storage;\n}\n\nconst server = new Server(\n {\n name: \"codemap-flow\",\n version: \"3.2.0\",\n },\n {\n capabilities: {\n tools: {},\n },\n }\n);\n\n// ============ Tools ============\n\nserver.setRequestHandler(ListToolsRequestSchema, async () => {\n return {\n tools: [\n {\n name: \"codemap_impact\",\n description: \"Analyze what would break if you change a function/class. Shows all callers and affected files with risk assessment.\",\n inputSchema: {\n type: \"object\",\n properties: {\n target: {\n type: \"string\",\n description: \"Function or class name to analyze\",\n },\n depth: {\n type: \"number\",\n description: \"How many levels deep to analyze (default: 3)\",\n default: 3,\n },\n },\n required: [\"target\"],\n },\n },\n {\n name: \"codemap_trace_flow\",\n description: \"Trace the execution flow between two functions. Shows the complete call path from source to target.\",\n inputSchema: {\n type: \"object\",\n properties: {\n from: {\n type: \"string\",\n description: \"Starting function name\",\n },\n to: {\n type: \"string\",\n description: \"Target function name\",\n },\n },\n required: [\"from\", \"to\"],\n },\n },\n {\n name: \"codemap_callers\",\n description: \"Find all functions that call a specific function. Shows where and how a function is used.\",\n inputSchema: {\n type: \"object\",\n properties: {\n function: {\n type: \"string\",\n description: \"Function name to find callers for\",\n },\n },\n required: [\"function\"],\n },\n },\n ],\n };\n});\n\nserver.setRequestHandler(CallToolRequestSchema, async (request) => {\n const { name, arguments: args } = request.params;\n const db = getStorage();\n\n try {\n switch (name) {\n case \"codemap_impact\": {\n const target = args?.target as string;\n const depth = (args?.depth as number) || 3;\n\n // Find the target node(s)\n const nodes = db.searchNodesByName(target);\n\n if (nodes.length === 0) {\n return {\n content: [\n {\n type: \"text\",\n text: `No function or class found with name \"${target}\"`,\n },\n ],\n };\n }\n\n const targetNode = nodes[0];\n\n // Get impacted nodes\n const impacted = db.getImpactedNodes(targetNode.id, depth);\n\n // Get unique files\n const affectedFiles = new Set(impacted.map((n) => n.filePath));\n\n // Assess risk\n const directCallers = db.getResolvedCallers(targetNode.id);\n let risk = \"LOW\";\n if (directCallers.length > 10) risk = \"HIGH\";\n else if (directCallers.length > 5) risk = \"MEDIUM\";\n\n const response = `# Impact Analysis: ${targetNode.name}\n\n**Location:** ${targetNode.filePath}:${targetNode.startLine}\n**Type:** ${targetNode.type}\n**Risk Level:** ${risk}\n\n## Direct Callers (${directCallers.length})\n${directCallers.slice(0, 10).map((c) => `- ${c.name} in ${c.filePath}:${c.startLine}`).join(\"\\n\")}\n${directCallers.length > 10 ? `\\n... and ${directCallers.length - 10} more` : \"\"}\n\n## Total Impact\n- **Affected functions:** ${impacted.length}\n- **Affected files:** ${affectedFiles.size}\n\n## Affected Files\n${[...affectedFiles].slice(0, 20).map((f) => `- ${f}`).join(\"\\n\")}\n${affectedFiles.size > 20 ? `\\n... and ${affectedFiles.size - 20} more` : \"\"}\n\n⚠️ **Recommendation:** ${risk === \"HIGH\" ? \"High-risk change. Review all callers before modifying.\" : risk === \"MEDIUM\" ? \"Moderate risk. Test affected files after changes.\" : \"Low risk. Changes unlikely to cause wide impact.\"}\n`;\n\n return {\n content: [{ type: \"text\", text: response }],\n };\n }\n\n case \"codemap_trace_flow\": {\n const from = args?.from as string;\n const to = args?.to as string;\n\n // Find source and target nodes\n const sourceNodes = db.searchNodesByName(from);\n const targetNodes = db.searchNodesByName(to);\n\n if (sourceNodes.length === 0) {\n return {\n content: [{ type: \"text\", text: `Source function \"${from}\" not found` }],\n };\n }\n\n if (targetNodes.length === 0) {\n return {\n content: [{ type: \"text\", text: `Target function \"${to}\" not found` }],\n };\n }\n\n const sourceNode = sourceNodes[0];\n const targetNode = targetNodes[0];\n\n // Trace path\n const path = db.traceCallPath(sourceNode.id, targetNode.id);\n\n if (!path) {\n return {\n content: [\n {\n type: \"text\",\n text: `No call path found from \"${from}\" to \"${to}\". They may not be connected.`,\n },\n ],\n };\n }\n\n const response = `# Execution Flow: ${from} → ${to}\n\n${path.nodes\n .map(\n (n, i) =>\n `${i + 1}. **${n.name}**\\n File: ${n.file}:${n.line}${i < path.nodes.length - 1 ? \"\\n ↓ calls\" : \"\"}`\n )\n .join(\"\\n\\n\")}\n\n**Total steps:** ${path.nodes.length}\n`;\n\n return {\n content: [{ type: \"text\", text: response }],\n };\n }\n\n case \"codemap_callers\": {\n const functionName = args?.function as string;\n\n // Find the function\n const nodes = db.searchNodesByName(functionName);\n\n if (nodes.length === 0) {\n return {\n content: [{ type: \"text\", text: `Function \"${functionName}\" not found` }],\n };\n }\n\n const targetNode = nodes[0];\n\n // Get all callers\n const callers = db.getResolvedCallers(targetNode.id);\n\n if (callers.length === 0) {\n return {\n content: [\n {\n type: \"text\",\n text: `No callers found for \"${functionName}\". It may be unused or only called externally.`,\n },\n ],\n };\n }\n\n const response = `# Callers of ${functionName}\n\n**Function:** ${targetNode.name} (${targetNode.type})\n**Location:** ${targetNode.filePath}:${targetNode.startLine}\n**Total callers:** ${callers.length}\n\n## Who Calls This Function\n\n${callers\n .map(\n (c) => `- **${c.name}** (${c.type})\n File: ${c.filePath}:${c.startLine}`\n )\n .join(\"\\n\\n\")}\n`;\n\n return {\n content: [{ type: \"text\", text: response }],\n };\n }\n\n default:\n return {\n content: [{ type: \"text\", text: `Unknown tool: ${name}` }],\n isError: true,\n };\n }\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n return {\n content: [{ type: \"text\", text: `Error: ${errorMessage}` }],\n isError: true,\n };\n }\n});\n\n// Start server\nconst transport = new StdioServerTransport();\nserver.connect(transport).catch((error) => {\n console.error(\"Failed to start MCP server:\", error);\n process.exit(1);\n});\n"],"mappings":";;;;;;;AAKA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAG3B,IAAM,UAAU,QAAQ,IAAI,mBAAmB;AAC/C,IAAM,eAAe,QAAQ,IAAI,wBAAwB,QAAQ,IAAI;AAErE,IAAI,UAA8B;AAElC,SAAS,aAA0B;AACjC,MAAI,CAAC,SAAS;AACZ,UAAM,SAAS,QAAQ,cAAc,OAAO;AAC5C,QAAI,CAAC,WAAW,MAAM,GAAG;AACvB,YAAM,IAAI,MAAM,iCAAiC,MAAM,8BAA8B;AAAA,IACvF;AACA,cAAU,IAAI,YAAY,MAAM;AAAA,EAClC;AACA,SAAO;AACT;AAEA,IAAM,SAAS,IAAI;AAAA,EACjB;AAAA,IACE,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,cAAc;AAAA,MACZ,OAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF;AAIA,OAAO,kBAAkB,wBAAwB,YAAY;AAC3D,SAAO;AAAA,IACL,OAAO;AAAA,MACL;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,aAAa;AAAA,UACX,MAAM;AAAA,UACN,YAAY;AAAA,YACV,QAAQ;AAAA,cACN,MAAM;AAAA,cACN,aAAa;AAAA,YACf;AAAA,YACA,OAAO;AAAA,cACL,MAAM;AAAA,cAC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,YACL,SAAS;AAAA,cACP;AAAA,gBACE,MAAM;AAAA,gBACN,MAAM,yBAAyB,YAAY;AAAA,cAC7C;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAEA,cAAM,WAAW,gBAAgB,YAAY;AAAA;AAAA,gBAErC,WAAW,IAAI,KAAK,WAAW,IAAI;AAAA,gBACnC,WAAW,QAAQ,IAAI,WAAW,SAAS;AAAA,qBACtC,QAAQ,MAAM;AAAA;AAAA;AAAA;AAAA,EAIjC,QACC;AAAA,UACC,CAAC,MAAM,OAAO,EAAE,IAAI,OAAO,EAAE,IAAI;AAAA,UAC3B,EAAE,QAAQ,IAAI,EAAE,SAAS;AAAA,QACjC,EACC,KAAK,MAAM,CAAC;AAAA;AAGP,eAAO;AAAA,UACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,SAAS,CAAC;AAAA,QAC5C;AAAA,MACF;AAAA,MAEA;AACE,eAAO;AAAA,UACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,iBAAiB,IAAI,GAAG,CAAC;AAAA,UACzD,SAAS;AAAA,QACX;AAAA,IACJ;AAAA,EACF,SAAS,OAAgB;AACvB,UAAM,eAAe,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC1E,WAAO;AAAA,MACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,UAAU,YAAY,GAAG,CAAC;AAAA,MAC1D,SAAS;AAAA,IACX;AAAA,EACF;AACF,CAAC;AAGD,IAAM,YAAY,IAAI,qBAAqB;AAC3C,OAAO,QAAQ,SAAS,EAAE,MAAM,CAAC,UAAU;AACzC,UAAQ,MAAM,+BAA+B,KAAK;AAClD,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/mcp/flow-server.ts"],"sourcesContent":["/**\n * MCP Server for CodeMap Flow Edition\n * Provides 3 focused tools: impact analysis, flow tracing, and caller lookup\n */\n\nimport { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport {\n CallToolRequestSchema,\n ListToolsRequestSchema,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { FlowStorage } from \"../flow/storage.js\";\nimport { resolve } from \"path\";\nimport { existsSync } from \"fs\";\n\n// Get config from environment\nconst DB_PATH = process.env.CODEMAP_DB_PATH || \".codemap/graph.db\";\nconst PROJECT_ROOT = process.env.CODEMAP_PROJECT_ROOT || process.cwd();\n\nlet storage: FlowStorage | null = null;\n\nfunction getStorage(): FlowStorage {\n if (!storage) {\n const dbPath = resolve(PROJECT_ROOT, DB_PATH);\n if (!existsSync(dbPath)) {\n throw new Error(`CodeMap database not found at ${dbPath}. Run 'codemap index' first.`);\n }\n storage = new FlowStorage(dbPath);\n }\n return storage;\n}\n\nconst server = new Server(\n {\n name: \"codemap-flow\",\n version: \"3.5.0\",\n },\n {\n capabilities: {\n tools: {},\n },\n }\n);\n\n// ============ Tools ============\n\nserver.setRequestHandler(ListToolsRequestSchema, async () => {\n return {\n tools: [\n {\n name: \"codemap_impact\",\n description: \"Analyze what would break if you change a function/class. Shows all callers and affected files with risk assessment.\",\n inputSchema: {\n type: \"object\",\n properties: {\n target: {\n type: \"string\",\n description: \"Function or class name to analyze\",\n },\n depth: {\n type: \"number\",\n description: \"How many levels deep to analyze (default: 3)\",\n default: 3,\n },\n },\n required: [\"target\"],\n },\n },\n {\n name: \"codemap_trace_flow\",\n description: \"Trace the execution flow between two functions. Shows the complete call path from source to target.\",\n inputSchema: {\n type: \"object\",\n properties: {\n from: {\n type: \"string\",\n description: \"Starting function name\",\n },\n to: {\n type: \"string\",\n description: \"Target function name\",\n },\n },\n required: [\"from\", \"to\"],\n },\n },\n {\n name: \"codemap_callers\",\n description: \"Find all functions that call a specific function. Shows where and how a function is used.\",\n inputSchema: {\n type: \"object\",\n properties: {\n function: {\n type: \"string\",\n description: \"Function name to find callers for\",\n },\n },\n required: [\"function\"],\n },\n },\n ],\n };\n});\n\nserver.setRequestHandler(CallToolRequestSchema, async (request) => {\n const { name, arguments: args } = request.params;\n const db = getStorage();\n\n try {\n switch (name) {\n case \"codemap_impact\": {\n const target = args?.target as string;\n const depth = (args?.depth as number) || 3;\n\n // Find the target node(s)\n const nodes = db.searchNodesByName(target);\n\n if (nodes.length === 0) {\n return {\n content: [\n {\n type: \"text\",\n text: `No function or class found with name \"${target}\"`,\n },\n ],\n };\n }\n\n const targetNode = nodes[0];\n\n // Get impacted nodes\n const impacted = db.getImpactedNodes(targetNode.id, depth);\n\n // Get unique files\n const affectedFiles = new Set(impacted.map((n) => n.filePath));\n\n // Assess risk\n const directCallers = db.getResolvedCallers(targetNode.id);\n let risk = \"LOW\";\n if (directCallers.length > 10) risk = \"HIGH\";\n else if (directCallers.length > 5) risk = \"MEDIUM\";\n\n const response = `# Impact Analysis: ${targetNode.name}\n\n**Location:** ${targetNode.filePath}:${targetNode.startLine}\n**Type:** ${targetNode.type}\n**Risk Level:** ${risk}\n\n## Direct Callers (${directCallers.length})\n${directCallers.slice(0, 10).map((c) => `- ${c.name} in ${c.filePath}:${c.startLine}`).join(\"\\n\")}\n${directCallers.length > 10 ? `\\n... and ${directCallers.length - 10} more` : \"\"}\n\n## Total Impact\n- **Affected functions:** ${impacted.length}\n- **Affected files:** ${affectedFiles.size}\n\n## Affected Files\n${[...affectedFiles].slice(0, 20).map((f) => `- ${f}`).join(\"\\n\")}\n${affectedFiles.size > 20 ? `\\n... and ${affectedFiles.size - 20} more` : \"\"}\n\n⚠️ **Recommendation:** ${risk === \"HIGH\" ? \"High-risk change. Review all callers before modifying.\" : risk === \"MEDIUM\" ? \"Moderate risk. Test affected files after changes.\" : \"Low risk. Changes unlikely to cause wide impact.\"}\n`;\n\n return {\n content: [{ type: \"text\", text: response }],\n };\n }\n\n case \"codemap_trace_flow\": {\n const from = args?.from as string;\n const to = args?.to as string;\n\n // Find source and target nodes\n const sourceNodes = db.searchNodesByName(from);\n const targetNodes = db.searchNodesByName(to);\n\n if (sourceNodes.length === 0) {\n return {\n content: [{ type: \"text\", text: `Source function \"${from}\" not found` }],\n };\n }\n\n if (targetNodes.length === 0) {\n return {\n content: [{ type: \"text\", text: `Target function \"${to}\" not found` }],\n };\n }\n\n const sourceNode = sourceNodes[0];\n const targetNode = targetNodes[0];\n\n // Trace path\n const path = db.traceCallPath(sourceNode.id, targetNode.id);\n\n if (!path) {\n return {\n content: [\n {\n type: \"text\",\n text: `No call path found from \"${from}\" to \"${to}\". They may not be connected.`,\n },\n ],\n };\n }\n\n const response = `# Execution Flow: ${from} → ${to}\n\n${path.nodes\n .map(\n (n, i) =>\n `${i + 1}. **${n.name}**\\n File: ${n.file}:${n.line}${i < path.nodes.length - 1 ? \"\\n ↓ calls\" : \"\"}`\n )\n .join(\"\\n\\n\")}\n\n**Total steps:** ${path.nodes.length}\n`;\n\n return {\n content: [{ type: \"text\", text: response }],\n };\n }\n\n case \"codemap_callers\": {\n const functionName = args?.function as string;\n\n // Find the function\n const nodes = db.searchNodesByName(functionName);\n\n if (nodes.length === 0) {\n return {\n content: [{ type: \"text\", text: `Function \"${functionName}\" not found` }],\n };\n }\n\n const targetNode = nodes[0];\n\n // Get all callers\n const callers = db.getResolvedCallers(targetNode.id);\n\n if (callers.length === 0) {\n return {\n content: [\n {\n type: \"text\",\n text: `No callers found for \"${functionName}\". It may be unused or only called externally.`,\n },\n ],\n };\n }\n\n const response = `# Callers of ${functionName}\n\n**Function:** ${targetNode.name} (${targetNode.type})\n**Location:** ${targetNode.filePath}:${targetNode.startLine}\n**Total callers:** ${callers.length}\n\n## Who Calls This Function\n\n${callers\n .map(\n (c) => `- **${c.name}** (${c.type})\n File: ${c.filePath}:${c.startLine}`\n )\n .join(\"\\n\\n\")}\n`;\n\n return {\n content: [{ type: \"text\", text: response }],\n };\n }\n\n default:\n return {\n content: [{ type: \"text\", text: `Unknown tool: ${name}` }],\n isError: true,\n };\n }\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n return {\n content: [{ type: \"text\", text: `Error: ${errorMessage}` }],\n isError: true,\n };\n }\n});\n\n// Start server\nconst transport = new StdioServerTransport();\nserver.connect(transport).catch((error) => {\n console.error(\"Failed to start MCP server:\", error);\n process.exit(1);\n});\n"],"mappings":";;;;;;;AAKA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAG3B,IAAM,UAAU,QAAQ,IAAI,mBAAmB;AAC/C,IAAM,eAAe,QAAQ,IAAI,wBAAwB,QAAQ,IAAI;AAErE,IAAI,UAA8B;AAElC,SAAS,aAA0B;AACjC,MAAI,CAAC,SAAS;AACZ,UAAM,SAAS,QAAQ,cAAc,OAAO;AAC5C,QAAI,CAAC,WAAW,MAAM,GAAG;AACvB,YAAM,IAAI,MAAM,iCAAiC,MAAM,8BAA8B;AAAA,IACvF;AACA,cAAU,IAAI,YAAY,MAAM;AAAA,EAClC;AACA,SAAO;AACT;AAEA,IAAM,SAAS,IAAI;AAAA,EACjB;AAAA,IACE,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,cAAc;AAAA,MACZ,OAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF;AAIA,OAAO,kBAAkB,wBAAwB,YAAY;AAC3D,SAAO;AAAA,IACL,OAAO;AAAA,MACL;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,aAAa;AAAA,UACX,MAAM;AAAA,UACN,YAAY;AAAA,YACV,QAAQ;AAAA,cACN,MAAM;AAAA,cACN,aAAa;AAAA,YACf;AAAA,YACA,OAAO;AAAA,cACL,MAAM;AAAA,cACN,aAAa;AAAA,cACb,SAAS;AAAA,YACX;AAAA,UACF;AAAA,UACA,UAAU,CAAC,QAAQ;AAAA,QACrB;AAAA,MACF;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,aAAa;AAAA,UACX,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