|
5 | 5 | import { |
6 | 6 | buildFullPatternCard, |
7 | 7 | buildPatternContent, |
8 | | - buildScanFirstPatternContent, |
9 | | - buildSearchResultsContent, |
10 | 8 | } from "@/mcp-content-builders.js"; |
11 | 9 | import type { |
12 | 10 | Elicitation, |
@@ -34,10 +32,6 @@ import { |
34 | 32 | isSearchTooBroad, |
35 | 33 | } from "@/tools/elicitation-helpers.js"; |
36 | 34 | import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; |
37 | | -import matter from "gray-matter"; |
38 | | -import { globSync } from "glob"; |
39 | | -import path from "node:path"; |
40 | | -import { readFileSync } from "node:fs"; |
41 | 35 |
|
42 | 36 | /** |
43 | 37 | * Telemetry counters for cache performance |
@@ -82,53 +76,6 @@ function normalizeContentBlocks( |
82 | 76 | })); |
83 | 77 | } |
84 | 78 |
|
85 | | -function extractFirstCodeFence(body: string): { code: string; language?: string } | null { |
86 | | - const fence = /```(\\w+)?\\n([\\s\\S]*?)\\n```/m.exec(body); |
87 | | - if (!fence) return null; |
88 | | - return { language: fence[1], code: fence[2].trim() }; |
89 | | -} |
90 | | - |
91 | | -function extractSection(body: string, heading: string): string | null { |
92 | | - const pattern = new RegExp(`^##\\s+${heading}\\s*$`, "m"); |
93 | | - const match = pattern.exec(body); |
94 | | - if (!match) return null; |
95 | | - const start = match.index + match[0].length; |
96 | | - const rest = body.slice(start); |
97 | | - const next = rest.search(/^##\\s+/m); |
98 | | - return (next === -1 ? rest : rest.slice(0, next)).trim(); |
99 | | -} |
100 | | - |
101 | | -function extractFirstParagraph(text: string | null): string | null { |
102 | | - if (!text) return null; |
103 | | - const cleaned = text.replace(/```[\\s\\S]*?```/g, "").trim(); |
104 | | - const para = cleaned.split(/\\n\\n+/)[0]?.trim(); |
105 | | - return para || null; |
106 | | -} |
107 | | - |
108 | | -function findMdxPathBySlug(id: string): string | null { |
109 | | - const root = path.resolve(process.cwd(), "../../content/published/patterns"); |
110 | | - const matches = globSync(`${root}/**/${id}.mdx`); |
111 | | - return matches[0] || null; |
112 | | -} |
113 | | - |
114 | | -function extractMdxFields(id: string): { |
115 | | - summary?: string; |
116 | | - guideline?: string; |
117 | | - rationale?: string; |
118 | | - example?: { code: string; language?: string }; |
119 | | -} { |
120 | | - const filePath = findMdxPathBySlug(id); |
121 | | - if (!filePath) return {}; |
122 | | - const raw = readFileSync(filePath, "utf8"); |
123 | | - const { data, content } = matter(raw); |
124 | | - const summary = typeof data.summary === "string" ? data.summary : undefined; |
125 | | - const guideline = extractFirstParagraph(extractSection(content, "Guideline")); |
126 | | - const rationale = extractFirstParagraph(extractSection(content, "Rationale")); |
127 | | - const goodExampleSection = extractSection(content, "Good Example") || extractSection(content, "Example"); |
128 | | - const example = extractFirstCodeFence(goodExampleSection || content) || undefined; |
129 | | - return { summary, guideline, rationale, example }; |
130 | | -} |
131 | | - |
132 | 79 | function extractApiNames(text: string): string[] { |
133 | 80 | const matches = text.match(/\\b(Effect|Layer|Stream|Schedule|Metric|Ref|Queue|PubSub)\\.\\w+/g); |
134 | 81 | return matches ? Array.from(new Set(matches)).slice(0, 6) : []; |
|
0 commit comments