catalyst-core-internal 0.1.4 → 0.1.6

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.
Files changed (43) hide show
  1. package/bin/catalyst.js +1 -8
  2. package/changelog.md +21 -0
  3. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/BridgeMessageValidator.kt +1 -1
  4. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CustomWebview.kt +1 -12
  5. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +3 -18
  6. package/dist/native/buildAppAndroid.js +2 -2
  7. package/dist/native/buildAppIos.js +17 -10
  8. package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +2 -13
  9. package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +0 -6
  10. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.pbxproj +0 -4
  11. package/mcp_v2/conversion-tasks.json +326 -0
  12. package/mcp_v2/knowledge-base.json +1068 -0
  13. package/mcp_v2/lib/helpers.js +170 -0
  14. package/mcp_v2/mcp.js +563 -0
  15. package/mcp_v2/package.json +13 -0
  16. package/mcp_v2/schema.sql +88 -0
  17. package/mcp_v2/setup.js +282 -0
  18. package/mcp_v2/tools/build.js +686 -0
  19. package/mcp_v2/tools/config.js +453 -0
  20. package/mcp_v2/tools/conversion.js +799 -0
  21. package/mcp_v2/tools/debug.js +113 -0
  22. package/mcp_v2/tools/knowledge.js +219 -0
  23. package/mcp_v2/tools/sync.js +23 -0
  24. package/mcp_v2/tools/tasks.js +945 -0
  25. package/package.json +7 -15
  26. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/plugins/CatalystPlugin.kt +0 -7
  27. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/plugins/GeneratedPluginIndex.kt +0 -6
  28. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/plugins/PluginBridge.kt +0 -253
  29. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/plugins/PluginBridgeTest.kt +0 -139
  30. package/dist/native/internal-plugins/device-info-plugin/android/DeviceInfoPlugin.kt +0 -43
  31. package/dist/native/internal-plugins/device-info-plugin/ios/DeviceInfoPlugin.swift +0 -28
  32. package/dist/native/internal-plugins/device-info-plugin/manifest.json +0 -19
  33. package/dist/native/internalPluginUtils.js +0 -1
  34. package/dist/native/iosnativeWebView/Sources/Core/Plugins/CatalystPlugin.swift +0 -5
  35. package/dist/native/iosnativeWebView/Sources/Core/Plugins/GeneratedPluginIndex.swift +0 -6
  36. package/dist/native/iosnativeWebView/Sources/Core/Plugins/PluginBridge.swift +0 -364
  37. package/dist/native/iosnativeWebView/Sources/Core/WebView/WeakScriptMessageHandler.swift +0 -14
  38. package/dist/native/iosnativeWebView/iosnativeWebViewTests/PluginBridgeTests.swift +0 -160
  39. package/dist/native/plugin-bridge/PluginBridge.js +0 -1
  40. package/dist/native/pluginComposerAndroid.js +0 -9
  41. package/dist/native/pluginComposerIos.js +0 -7
  42. package/dist/scripts/plugins.js +0 -1
  43. package/license +0 -10
@@ -0,0 +1,282 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Catalyst MCP v2 — setup.js
4
+ * Run once: npx catalyst-mcp-setup (or node setup.js from mcp_v2/)
5
+ *
6
+ * Steps:
7
+ * 1. Verify this is a valid catalyst-core project
8
+ * 2. Create context.db, run schema.sql
9
+ * 3. Seed framework_knowledge from knowledge-base.json (static rows)
10
+ * 4. Seed known_errors from knowledge-base.json known_errors section
11
+ * 5. Run sync_catalyst_docs once (dynamic sitemap rows)
12
+ */
13
+
14
+ const fs = require("fs")
15
+ const path = require("path")
16
+ const Database = require("better-sqlite3")
17
+ const https = require("https")
18
+ const crypto = require("crypto")
19
+
20
+ const MCP_DIR = __dirname
21
+ const DB_PATH = path.join(MCP_DIR, "context.db")
22
+ const SCHEMA_PATH = path.join(MCP_DIR, "schema.sql")
23
+ const KB_PATH = path.join(MCP_DIR, "knowledge-base.json")
24
+ const SITEMAP_URL = "https://catalyst.1mg.com/public_docs/sitemap.xml"
25
+ const supportedCatalystPackages = ["catalyst-core", "catalyst-core-internal"]
26
+
27
+ // ── 1. Find & validate catalyst project ──────────────────────────────────────
28
+
29
+ function findCatalystRoot() {
30
+ let dir = process.cwd()
31
+ while (dir !== path.parse(dir).root) {
32
+ const pkgPath = path.join(dir, "package.json")
33
+ if (fs.existsSync(pkgPath)) {
34
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
35
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies }
36
+ const catalystPackageName = supportedCatalystPackages.find((packageName) => deps[packageName])
37
+ if (catalystPackageName) {
38
+ return { dir, pkg, catalystPackageName, version: deps[catalystPackageName] }
39
+ }
40
+ }
41
+ dir = path.dirname(dir)
42
+ }
43
+ return null
44
+ }
45
+
46
+ // ── 2. DB init ────────────────────────────────────────────────────────────────
47
+
48
+ function initDb() {
49
+ const schema = fs.readFileSync(SCHEMA_PATH, "utf8")
50
+ const db = new Database(DB_PATH)
51
+ db.exec(schema)
52
+ return db
53
+ }
54
+
55
+ // ── 3 & 4. Seed from knowledge-base.json ─────────────────────────────────────
56
+
57
+ function seedKnowledgeBase(db, projectInfo) {
58
+ const kb = JSON.parse(fs.readFileSync(KB_PATH, "utf8"))
59
+
60
+ // DELETE existing static rows so re-runs reflect updated knowledge-base.json
61
+ db.prepare(`DELETE FROM framework_knowledge WHERE source = 'static'`).run()
62
+ db.prepare(`DELETE FROM known_errors`).run()
63
+
64
+ const insertKnowledge = db.prepare(`
65
+ INSERT INTO framework_knowledge (section, title, content, layer, source, tags, github_files)
66
+ VALUES (@section, @title, @content, @layer, @source, @tags, @github_files)
67
+ `)
68
+
69
+ const insertError = db.prepare(`
70
+ INSERT INTO known_errors (symptom, cause, fix, layer, tags)
71
+ VALUES (@symptom, @cause, @fix, @layer, @tags)
72
+ `)
73
+
74
+ let knowledgeCount = 0
75
+ let errorCount = 0
76
+
77
+ const seedAll = db.transaction(() => {
78
+ for (const entry of kb) {
79
+ if (entry.section === "known_errors") {
80
+ // known_errors entries encode symptom/cause/fix in content as:
81
+ // "Symptom: ... Cause: ... Fix: ..."
82
+ const content = entry.content || ""
83
+ const symptomMatch = content.match(/Symptom:\s*([^.]+\.?)/i)
84
+ const causeMatch = content.match(/Cause:\s*([^.]+\.?)/i)
85
+ const fixMatch = content.match(/Fix:\s*([\s\S]+)/i)
86
+ insertError.run({
87
+ symptom: symptomMatch ? symptomMatch[1].trim() : entry.title,
88
+ cause: causeMatch ? causeMatch[1].trim() : "",
89
+ fix: fixMatch ? fixMatch[1].trim() : "",
90
+ layer: entry.layer,
91
+ tags: JSON.stringify(entry.tags || []),
92
+ })
93
+ errorCount++
94
+ } else {
95
+ insertKnowledge.run({
96
+ section: entry.section,
97
+ title: entry.title,
98
+ content: entry.content,
99
+ layer: entry.layer,
100
+ source: "static",
101
+ tags: JSON.stringify(entry.tags || []),
102
+ github_files: entry.github_files ? JSON.stringify(entry.github_files) : null,
103
+ })
104
+ knowledgeCount++
105
+ }
106
+ }
107
+ })
108
+
109
+ seedAll()
110
+ console.log(` ✓ Seeded ${knowledgeCount} knowledge entries`)
111
+ console.log(` ✓ Seeded ${errorCount} known_errors entries`)
112
+
113
+ // Store project context
114
+ db.prepare(
115
+ `
116
+ INSERT OR REPLACE INTO project_context (id, repo_path, package_name, catalyst_version, detected_at)
117
+ VALUES (1, @repo_path, @package_name, @catalyst_version, datetime('now'))
118
+ `
119
+ ).run({
120
+ repo_path: projectInfo.dir,
121
+ package_name: projectInfo.pkg.name || "unknown",
122
+ catalyst_version: projectInfo.version,
123
+ })
124
+ console.log(
125
+ ` ✓ Project context stored (${projectInfo.pkg.name}, ${projectInfo.catalystPackageName}@${projectInfo.version})`
126
+ )
127
+ }
128
+
129
+ // ── 5. sync_catalyst_docs (initial run) ───────────────────────────────────────
130
+
131
+ function fetchUrl(url) {
132
+ return new Promise((resolve, reject) => {
133
+ const mod = url.startsWith("https") ? https : require("http")
134
+ mod.get(url, (res) => {
135
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
136
+ return fetchUrl(res.headers.location).then(resolve).catch(reject)
137
+ }
138
+ let data = ""
139
+ res.on("data", (chunk) => (data += chunk))
140
+ res.on("end", () => resolve(data))
141
+ }).on("error", reject)
142
+ })
143
+ }
144
+
145
+ function parseSitemapUrls(xml) {
146
+ const matches = xml.match(/<loc>(.*?)<\/loc>/g) || []
147
+ return matches.map((m) => m.replace(/<\/?loc>/g, "").trim())
148
+ }
149
+
150
+ function stripHtml(html) {
151
+ // Very simple strip — good enough for catalyst docs
152
+ return html
153
+ .replace(/<script[\s\S]*?<\/script>/gi, "")
154
+ .replace(/<style[\s\S]*?<\/style>/gi, "")
155
+ .replace(/<[^>]+>/g, " ")
156
+ .replace(/\s+/g, " ")
157
+ .trim()
158
+ }
159
+
160
+ function contentHash(text) {
161
+ return crypto.createHash("sha256").update(text).digest("hex").slice(0, 16)
162
+ }
163
+
164
+ // Kept for manual/live sync flows; setup does not invoke it by default.
165
+ // eslint-disable-next-line no-unused-vars
166
+ async function syncCatalystDocs(db) {
167
+ console.log("\n Fetching sitemap...")
168
+ let xml
169
+ try {
170
+ xml = await fetchUrl(SITEMAP_URL)
171
+ } catch (e) {
172
+ console.warn(` ⚠ Could not fetch sitemap (${e.message}). Skipping live docs sync.`)
173
+ console.warn(" You can run sync later via the sync_catalyst_docs MCP tool.")
174
+ return
175
+ }
176
+
177
+ const urls = parseSitemapUrls(xml)
178
+ console.log(` Found ${urls.length} URLs in sitemap`)
179
+
180
+ const insertKnowledge = db.prepare(`
181
+ INSERT INTO framework_knowledge (section, title, content, layer, source, tags, url)
182
+ VALUES (@section, @title, @content, @layer, 'sitemap', '[]', @url)
183
+ `)
184
+
185
+ const insertSnapshot = db.prepare(`
186
+ INSERT INTO doc_snapshots (url, content_hash, slot) VALUES (@url, @hash, 'curr')
187
+ `)
188
+
189
+ const insertLink = db.prepare(`
190
+ INSERT INTO linkage_map (url, knowledge_id) VALUES (@url, @knowledge_id)
191
+ `)
192
+
193
+ let synced = 0
194
+ let failed = 0
195
+
196
+ for (const url of urls) {
197
+ try {
198
+ const html = await fetchUrl(url)
199
+ const text = stripHtml(html)
200
+ const hash = contentHash(text)
201
+
202
+ // Extract a title from <title> tag if present
203
+ const titleMatch = html.match(/<title[^>]*>(.*?)<\/title>/i)
204
+ const title = titleMatch ? titleMatch[1].trim() : url.split("/").pop() || url
205
+
206
+ // Truncate content to 2000 chars to keep DB lean
207
+ const content = text.slice(0, 2000)
208
+
209
+ db.transaction(() => {
210
+ const row = insertKnowledge.run({
211
+ section: "sitemap",
212
+ title,
213
+ content,
214
+ layer: "Component",
215
+ url,
216
+ })
217
+ insertSnapshot.run({ url, hash })
218
+ insertLink.run({ url, knowledge_id: row.lastInsertRowid })
219
+ })()
220
+
221
+ synced++
222
+ process.stdout.write(`\r Synced ${synced}/${urls.length} pages...`)
223
+ } catch (e) {
224
+ failed++
225
+ }
226
+ }
227
+
228
+ console.log(`\n ✓ Synced ${synced} pages (${failed} failed)`)
229
+ }
230
+
231
+ // ── Main ──────────────────────────────────────────────────────────────────────
232
+
233
+ async function main() {
234
+ console.log("Catalyst MCP v2 — Setup\n")
235
+
236
+ // 1. Validate catalyst project
237
+ const projectInfo = findCatalystRoot()
238
+ if (!projectInfo) {
239
+ console.error(
240
+ "✗ No catalyst-core or catalyst-core-internal dependency found in any package.json above this directory."
241
+ )
242
+ console.error(" Run setup from inside your catalyst project.")
243
+ process.exit(1)
244
+ }
245
+ console.log(`✓ Catalyst project: ${projectInfo.pkg.name || projectInfo.dir}`)
246
+ console.log(` ${projectInfo.catalystPackageName}@${projectInfo.version}`)
247
+
248
+ // 2. Init DB
249
+ console.log("\nInitializing context.db...")
250
+ const db = initDb()
251
+ console.log(` ✓ DB created at ${DB_PATH}`)
252
+
253
+ // 3 & 4. Seed static knowledge
254
+ console.log("\nSeeding knowledge-base.json...")
255
+ seedKnowledgeBase(db, projectInfo)
256
+
257
+ // 5. Initial sitemap sync — disabled (slow, use sync_catalyst_docs MCP tool manually)
258
+ // console.log('\nRunning initial sync_catalyst_docs...');
259
+ // await syncCatalystDocs(db);
260
+
261
+ db.close()
262
+ console.log("\n✓ Setup complete. MCP is ready.\n")
263
+ const mcpConfig = JSON.stringify(
264
+ {
265
+ "catalyst-mcp": {
266
+ command: "node",
267
+ args: [path.join(MCP_DIR, "mcp.js")],
268
+ disabledTools: [],
269
+ disabled: false,
270
+ },
271
+ },
272
+ null,
273
+ 2
274
+ )
275
+ console.log("Add to your MCP config (Claude, Cursor, Windsurf, or any MCP-compatible client):")
276
+ console.log(mcpConfig)
277
+ }
278
+
279
+ main().catch((e) => {
280
+ console.error("Setup failed:", e.message)
281
+ process.exit(1)
282
+ })