catalyst-core-internal 0.1.3 → 0.1.5

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