catalyst-core-internal 0.1.2 → 0.1.4

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 (53) hide show
  1. package/README.md +4 -4
  2. package/bin/catalyst.js +8 -1
  3. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/BridgeMessageValidator.kt +3 -11
  4. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CustomWebview.kt +12 -1
  5. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +18 -3
  6. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/plugins/CatalystPlugin.kt +7 -0
  7. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/plugins/GeneratedPluginIndex.kt +6 -0
  8. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/plugins/PluginBridge.kt +253 -0
  9. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/SecurityBridgeTest.kt +199 -0
  10. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/plugins/PluginBridgeTest.kt +139 -0
  11. package/dist/native/bridge/hooks.js +4 -4
  12. package/dist/native/bridge/useBaseHook.js +5 -4
  13. package/dist/native/bridge/utils/NativeBridge.js +4 -4
  14. package/dist/native/buildAppAndroid.js +2 -2
  15. package/dist/native/buildAppIos.js +10 -17
  16. package/dist/native/internal-plugins/device-info-plugin/android/DeviceInfoPlugin.kt +43 -0
  17. package/dist/native/internal-plugins/device-info-plugin/ios/DeviceInfoPlugin.swift +28 -0
  18. package/dist/native/internal-plugins/device-info-plugin/manifest.json +19 -0
  19. package/dist/native/internalPluginUtils.js +1 -0
  20. package/dist/native/iosnativeWebView/Sources/Core/Plugins/CatalystPlugin.swift +5 -0
  21. package/dist/native/iosnativeWebView/Sources/Core/Plugins/GeneratedPluginIndex.swift +6 -0
  22. package/dist/native/iosnativeWebView/Sources/Core/Plugins/PluginBridge.swift +364 -0
  23. package/dist/native/iosnativeWebView/Sources/Core/Utils/CacheManager.swift +13 -2
  24. package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +13 -2
  25. package/dist/native/iosnativeWebView/Sources/Core/WebView/WeakScriptMessageHandler.swift +14 -0
  26. package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +6 -0
  27. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.pbxproj +4 -0
  28. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +36 -0
  29. package/dist/native/iosnativeWebView/iosnativeWebView.xctestplan +1 -0
  30. package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeCommandHandlerSecurityTests.swift +212 -0
  31. package/dist/native/iosnativeWebView/iosnativeWebViewTests/FrameworkServerUtilsTests.swift +14 -4
  32. package/dist/native/iosnativeWebView/iosnativeWebViewTests/PluginBridgeTests.swift +160 -0
  33. package/dist/native/iosnativeWebView/iosnativeWebViewTests/ScreenSecureManagerTests.swift +121 -0
  34. package/dist/native/iosnativeWebView/iosnativeWebViewTests/WebViewTests.swift +9 -21
  35. package/dist/native/plugin-bridge/PluginBridge.js +1 -0
  36. package/dist/native/pluginComposerAndroid.js +9 -0
  37. package/dist/native/pluginComposerIos.js +7 -0
  38. package/dist/scripts/plugins.js +1 -0
  39. package/package.json +3 -2
  40. package/mcp_v2/conversion-tasks.json +0 -371
  41. package/mcp_v2/knowledge-base.json +0 -1450
  42. package/mcp_v2/lib/helpers.js +0 -145
  43. package/mcp_v2/mcp.js +0 -366
  44. package/mcp_v2/package.json +0 -13
  45. package/mcp_v2/schema.sql +0 -88
  46. package/mcp_v2/setup.js +0 -262
  47. package/mcp_v2/tools/build.js +0 -449
  48. package/mcp_v2/tools/config.js +0 -262
  49. package/mcp_v2/tools/conversion.js +0 -492
  50. package/mcp_v2/tools/debug.js +0 -62
  51. package/mcp_v2/tools/knowledge.js +0 -213
  52. package/mcp_v2/tools/sync.js +0 -21
  53. package/mcp_v2/tools/tasks.js +0 -844
@@ -1,213 +0,0 @@
1
- 'use strict';
2
-
3
- const https = require('https');
4
- const { findCatalystRoot } = require('../lib/helpers');
5
-
6
- let _db;
7
-
8
- // Keywords that signal the LLM wants a complete/live list rather than a concept explanation.
9
- // When a matched KB entry has github_files + query matches these, we auto-fetch from GitHub.
10
- const LIST_INTENT_PATTERNS = /\b(all|list|available|new|latest|complete|full|enumerate|what hooks|any hooks|what.*available|show.*all)\b/i;
11
-
12
- function init(db) {
13
- _db = db;
14
-
15
- // Migrate: add github_files column if missing (existing DBs)
16
- const cols = _db.prepare(`PRAGMA table_info(framework_knowledge)`).all().map(c => c.name);
17
- if (!cols.includes('github_files')) {
18
- _db.exec(`ALTER TABLE framework_knowledge ADD COLUMN github_files TEXT`);
19
- }
20
- // Drop always_fetch_github if it exists (replaced by intent detection)
21
- // SQLite can't DROP COLUMN before 3.35 — just leave it, it's ignored
22
-
23
- // Create FTS5 virtual table if not exists (standalone, not external-content)
24
- _db.exec(`
25
- CREATE VIRTUAL TABLE IF NOT EXISTS fk_fts USING fts5(
26
- title, content, tags, section,
27
- tokenize='unicode61 remove_diacritics 1'
28
- );
29
- `);
30
-
31
- // Populate FTS index if empty
32
- const count = _db.prepare(`SELECT count(*) as c FROM fk_fts`).get().c;
33
- if (count === 0) {
34
- _db.exec(`INSERT INTO fk_fts(rowid, title, content, tags, section) SELECT id, title, content, COALESCE(tags,''), section FROM framework_knowledge`);
35
- }
36
- }
37
-
38
- function fetchRaw(url) {
39
- return new Promise((resolve, reject) => {
40
- https.get(url, { headers: { 'User-Agent': 'catalyst-mcp/1.0' } }, res => {
41
- if (res.statusCode === 404) return resolve(null);
42
- if (res.statusCode !== 200) return reject(new Error(`HTTP ${res.statusCode}`));
43
- const chunks = [];
44
- res.on('data', c => chunks.push(c));
45
- res.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
46
- }).on('error', reject);
47
- });
48
- }
49
-
50
- // Fetch first available file — used for KB-miss GitHub fallback
51
- async function fetchFromGithub(files, installedVersion) {
52
- if (!files || files.length === 0) return null;
53
-
54
- const tag = installedVersion || 'main';
55
- const base = `https://raw.githubusercontent.com/tata1mg/catalyst-core/${tag}`;
56
-
57
- for (const file of files) {
58
- try {
59
- const content = await fetchRaw(`${base}/${file}`);
60
- if (content) return { file, tag, content: content.slice(0, 8000) };
61
- } catch (_) {}
62
- }
63
-
64
- // Retry with main if versioned tag failed
65
- if (tag !== 'main') {
66
- for (const file of files) {
67
- try {
68
- const content = await fetchRaw(`https://raw.githubusercontent.com/tata1mg/catalyst-core/main/${file}`);
69
- if (content) return { file, tag: 'main', content: content.slice(0, 8000) };
70
- } catch (_) {}
71
- }
72
- }
73
-
74
- return null;
75
- }
76
-
77
- // Fetch a specific single file — used for intent-based narrowed fetch
78
- async function fetchOneFromGithub(file, installedVersion) {
79
- const tag = installedVersion || 'main';
80
- try {
81
- const content = await fetchRaw(`https://raw.githubusercontent.com/tata1mg/catalyst-core/${tag}/${file}`);
82
- if (content) return { file, tag, content: content.slice(0, 8000) };
83
- } catch (_) {}
84
- // Retry with main
85
- if (tag !== 'main') {
86
- try {
87
- const content = await fetchRaw(`https://raw.githubusercontent.com/tata1mg/catalyst-core/main/${file}`);
88
- if (content) return { file, tag: 'main', content: content.slice(0, 8000) };
89
- } catch (_) {}
90
- }
91
- return null;
92
- }
93
-
94
- // Build FTS5 query string from keywords array — each term ORed, quoted for safety
95
- function buildFtsQuery(keywords) {
96
- return keywords
97
- .map(k => `"${k.replace(/"/g, '')}"`)
98
- .join(' OR ');
99
- }
100
-
101
- // Narrow down which github_file to fetch based on query keywords.
102
- // Avoids fetching all files when query is clearly about one specific hook/file.
103
- function narrowGithubFile(files, query) {
104
- if (!files || files.length <= 1) return files;
105
- const q = query.toLowerCase();
106
- // If query mentions a specific file hint, prefer that file
107
- for (const file of files) {
108
- const basename = file.split('/').pop().replace(/\.js$/, '').toLowerCase();
109
- if (q.includes(basename)) return [file];
110
- }
111
- // Default: return all (caller fetches first available)
112
- return files;
113
- }
114
-
115
- async function handle_query_knowledge({ query, keywords, section, github_files } = {}) {
116
- if (!query) return { error: 'query is required.' };
117
-
118
- // ── FTS5 search ────────────────────────────────────────────────────────────
119
- const searchTerms = (keywords && keywords.length > 0) ? keywords : [query];
120
- const ftsQuery = buildFtsQuery(searchTerms);
121
-
122
- let rows = [];
123
- try {
124
- // Join back to framework_knowledge to get github_files
125
- const sql = section
126
- ? `SELECT fk.title, fk.content, fk.tags, fk.section, fk.github_files
127
- FROM fk_fts
128
- JOIN framework_knowledge fk ON fk_fts.rowid = fk.id
129
- WHERE fk_fts MATCH ? AND fk_fts.section = ? ORDER BY rank LIMIT 6`
130
- : `SELECT fk.title, fk.content, fk.tags, fk.section, fk.github_files
131
- FROM fk_fts
132
- JOIN framework_knowledge fk ON fk_fts.rowid = fk.id
133
- WHERE fk_fts MATCH ? ORDER BY rank LIMIT 6`;
134
- rows = section
135
- ? _db.prepare(sql).all(ftsQuery, section)
136
- : _db.prepare(sql).all(ftsQuery);
137
- } catch (_) {
138
- // FTS syntax error — fall through to github
139
- }
140
-
141
- if (rows.length > 0) {
142
- // Find first matched entry that has github_files attached
143
- const entryWithFiles = rows.find(r => r.github_files);
144
- const parsedFiles = entryWithFiles ? JSON.parse(entryWithFiles.github_files) : null;
145
-
146
- // ── Intent detection: does the query want a live/complete list? ──────────
147
- const isListIntent = LIST_INTENT_PATTERNS.test(query);
148
-
149
- if (isListIntent && parsedFiles) {
150
- let installedVersion = null;
151
- try {
152
- const root = findCatalystRoot();
153
- installedVersion = root ? root.installedVersion : null;
154
- } catch (_) {}
155
-
156
- // Narrow to the most relevant file based on query keywords
157
- const targetFiles = narrowGithubFile(parsedFiles, query);
158
- const github = await fetchFromGithub(targetFiles, installedVersion);
159
-
160
- return {
161
- query,
162
- source: 'knowledge_base+github',
163
- results: rows.map(({ github_files, ...r }) => r),
164
- github_file: github ? github.file : null,
165
- github_tag: github ? github.tag : null,
166
- github_content: github ? github.content : null,
167
- installed_version: installedVersion,
168
- note: `${rows.length} KB entries matched. List intent detected — fetched latest source${github ? ` (${github.file}@${github.tag})` : ' (GitHub fetch failed)'}.`,
169
- };
170
- }
171
-
172
- // ── Standard KB hit: return results + hint about live source files ───────
173
- return {
174
- query,
175
- source: 'knowledge_base',
176
- results: rows.map(({ github_files, ...r }) => r),
177
- live_source_files: parsedFiles || null, // LLM can re-query with these if it needs fresher data
178
- note: `${rows.length} entries matched from local knowledge base.${parsedFiles ? ' Pass live_source_files as github_files in a follow-up query_knowledge call if you need the latest source.' : ''}`,
179
- };
180
- }
181
-
182
- // ── GitHub fallback (KB miss) ──────────────────────────────────────────────
183
- let installedVersion = null;
184
- try {
185
- const root = findCatalystRoot();
186
- installedVersion = root ? root.installedVersion : null;
187
- } catch (_) {}
188
-
189
- const github = await fetchFromGithub(github_files || [], installedVersion);
190
-
191
- if (github) {
192
- return {
193
- query,
194
- source: 'github',
195
- github_file: github.file,
196
- github_tag: github.tag,
197
- installed_version: installedVersion,
198
- content: github.content,
199
- note: `No KB match. Fetched source file '${github.file}' from catalyst-core@${github.tag} on GitHub.`,
200
- };
201
- }
202
-
203
- // ── Hard miss ──────────────────────────────────────────────────────────────
204
- return {
205
- query,
206
- source: 'none',
207
- results: [],
208
- llm_instruction: 'No match found in the knowledge base and no source file was provided for GitHub fallback. DO NOT search node_modules, dist, or the filesystem. Tell the user this topic is not fully covered in the knowledge base yet, and suggest they check the catalyst-core source directly at node_modules/catalyst-core/src/.',
209
- note: `No KB match for "${query}". If you know the relevant source file path, retry with github_files: ["src/path/to/file.js"].`,
210
- };
211
- }
212
-
213
- module.exports = { init, handle_query_knowledge };
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- let _db;
4
-
5
- function init(db) {
6
- _db = db;
7
- }
8
-
9
- function handle_sync_catalyst_docs({ force = false } = {}) {
10
- const snapshot_count = _db.prepare(`SELECT COUNT(*) as c FROM doc_snapshots`).get();
11
- const knowledge_count = _db.prepare(`SELECT COUNT(*) as c FROM framework_knowledge WHERE source = 'sitemap'`).get();
12
- return {
13
- _phase: 6,
14
- force,
15
- existing_snapshots: snapshot_count.c,
16
- sitemap_knowledge_rows: knowledge_count.c,
17
- message: 'Live sync not yet implemented (Phase 6). Run setup.js for initial sync.',
18
- };
19
- }
20
-
21
- module.exports = { init, handle_sync_catalyst_docs };