@veolab/discoverylab 1.2.0 → 1.2.2

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.
@@ -0,0 +1,334 @@
1
+ import {
2
+ DATA_DIR,
3
+ DB_PATH
4
+ } from "./chunk-TJ3H23LL.js";
5
+ import {
6
+ createJsonResult,
7
+ createTextResult
8
+ } from "./chunk-XKX6NBHF.js";
9
+
10
+ // src/mcp/tools/setup.ts
11
+ import { z } from "zod";
12
+ import { execSync } from "child_process";
13
+ import { existsSync, readFileSync } from "fs";
14
+ import { createRequire } from "module";
15
+ import { platform, homedir } from "os";
16
+ var requireFromHere = createRequire(import.meta.url);
17
+ var dependencies = [
18
+ {
19
+ name: "FFmpeg",
20
+ command: "ffmpeg -version",
21
+ versionPattern: /ffmpeg version (\d+\.\d+(?:\.\d+)?)/,
22
+ required: true,
23
+ description: "Video processing and export",
24
+ installHint: "brew install ffmpeg (macOS) or apt install ffmpeg (Linux)"
25
+ },
26
+ {
27
+ name: "Maestro CLI",
28
+ command: "",
29
+ // Special handling - check multiple paths
30
+ versionPattern: /(\d+\.\d+\.\d+)/,
31
+ required: false,
32
+ description: "Mobile app testing automation",
33
+ installHint: 'curl -Ls "https://get.maestro.mobile.dev" | bash'
34
+ },
35
+ {
36
+ name: "Playwright",
37
+ command: "",
38
+ // Special handling - avoid npx auto-install false positives
39
+ versionPattern: /(\d+\.\d+\.\d+)/,
40
+ required: false,
41
+ description: "Web app testing and browser automation",
42
+ installHint: "npm install -g playwright"
43
+ },
44
+ {
45
+ name: "Xcode CLI Tools",
46
+ command: "xcode-select -p",
47
+ versionPattern: /.*/,
48
+ required: false,
49
+ description: "iOS Simulator access (macOS only)",
50
+ installHint: "xcode-select --install"
51
+ },
52
+ {
53
+ name: "ADB",
54
+ command: "adb version",
55
+ versionPattern: /Android Debug Bridge version (\d+\.\d+\.\d+)/,
56
+ required: false,
57
+ description: "Android Emulator access",
58
+ installHint: "Install Android Studio or: brew install android-platform-tools"
59
+ }
60
+ ];
61
+ function checkDependency(dep) {
62
+ if (dep.name === "Maestro CLI") {
63
+ return checkMaestro(dep);
64
+ }
65
+ if (dep.name === "Playwright") {
66
+ return checkPlaywright(dep);
67
+ }
68
+ try {
69
+ const output = execSync(dep.command, { encoding: "utf-8", timeout: 5e3 }).trim();
70
+ const match = output.match(dep.versionPattern);
71
+ return {
72
+ installed: true,
73
+ version: match ? match[1] || "installed" : "installed"
74
+ };
75
+ } catch (error) {
76
+ return {
77
+ installed: false,
78
+ version: null,
79
+ error: error instanceof Error ? error.message : "Command failed"
80
+ };
81
+ }
82
+ }
83
+ function checkPlaywright(dep) {
84
+ try {
85
+ const pkgPath = requireFromHere.resolve("playwright/package.json");
86
+ const raw = readFileSync(pkgPath, "utf-8");
87
+ const pkg = JSON.parse(raw);
88
+ return {
89
+ installed: true,
90
+ version: typeof pkg.version === "string" && pkg.version.trim() ? pkg.version.trim() : "installed"
91
+ };
92
+ } catch (error) {
93
+ return {
94
+ installed: false,
95
+ version: null,
96
+ error: error instanceof Error ? error.message : "Playwright package not found"
97
+ };
98
+ }
99
+ }
100
+ function checkMaestro(dep) {
101
+ const homeDir = homedir();
102
+ const maestroPaths = [
103
+ `${homeDir}/.maestro/bin/maestro`,
104
+ "/usr/local/bin/maestro",
105
+ "/opt/homebrew/bin/maestro"
106
+ ];
107
+ try {
108
+ const output = execSync("maestro --version 2>/dev/null || maestro version 2>/dev/null", {
109
+ encoding: "utf-8",
110
+ timeout: 5e3,
111
+ shell: "/bin/bash"
112
+ }).trim();
113
+ const match = output.match(dep.versionPattern);
114
+ return {
115
+ installed: true,
116
+ version: match ? match[1] : "installed"
117
+ };
118
+ } catch {
119
+ }
120
+ for (const maestroPath of maestroPaths) {
121
+ if (existsSync(maestroPath)) {
122
+ try {
123
+ const output = execSync(`"${maestroPath}" --version 2>/dev/null || "${maestroPath}" version 2>/dev/null`, {
124
+ encoding: "utf-8",
125
+ timeout: 5e3,
126
+ shell: "/bin/bash"
127
+ }).trim();
128
+ const match = output.match(dep.versionPattern);
129
+ return {
130
+ installed: true,
131
+ version: match ? match[1] : "installed"
132
+ };
133
+ } catch {
134
+ return {
135
+ installed: true,
136
+ version: "installed"
137
+ };
138
+ }
139
+ }
140
+ }
141
+ return {
142
+ installed: false,
143
+ version: null,
144
+ error: "Maestro not found in PATH or common installation directories"
145
+ };
146
+ }
147
+ var setupStatusTool = {
148
+ name: "dlab.setup.status",
149
+ description: "Check the status of DiscoveryLab setup and all dependencies.",
150
+ inputSchema: z.object({}),
151
+ handler: async () => {
152
+ const results = [];
153
+ let allRequiredInstalled = true;
154
+ for (const dep of dependencies) {
155
+ if (dep.name === "Xcode CLI Tools" && platform() !== "darwin") {
156
+ continue;
157
+ }
158
+ const status = checkDependency(dep);
159
+ results.push({
160
+ name: dep.name,
161
+ installed: status.installed,
162
+ version: status.version,
163
+ required: dep.required,
164
+ description: dep.description,
165
+ installHint: status.installed ? null : dep.installHint
166
+ });
167
+ if (dep.required && !status.installed) {
168
+ allRequiredInstalled = false;
169
+ }
170
+ }
171
+ const dataReady = existsSync(DATA_DIR);
172
+ const dbReady = existsSync(DB_PATH);
173
+ return createJsonResult({
174
+ ready: allRequiredInstalled && dataReady,
175
+ platform: platform(),
176
+ dataDirectory: {
177
+ path: DATA_DIR,
178
+ exists: dataReady
179
+ },
180
+ database: {
181
+ path: DB_PATH,
182
+ exists: dbReady
183
+ },
184
+ dependencies: results,
185
+ summary: {
186
+ total: results.length,
187
+ installed: results.filter((r) => r.installed).length,
188
+ missing: results.filter((r) => !r.installed).length,
189
+ requiredMissing: results.filter((r) => r.required && !r.installed).map((r) => r.name)
190
+ }
191
+ });
192
+ }
193
+ };
194
+ var setupCheckTool = {
195
+ name: "dlab.setup.check",
196
+ description: "Quick check if a specific tool is installed.",
197
+ inputSchema: z.object({
198
+ tool: z.enum(["ffmpeg", "maestro", "playwright", "xcode", "adb"]).describe("Tool to check")
199
+ }),
200
+ handler: async (params) => {
201
+ const toolMap = {
202
+ ffmpeg: dependencies[0],
203
+ maestro: dependencies[1],
204
+ playwright: dependencies[2],
205
+ xcode: dependencies[3],
206
+ adb: dependencies[4]
207
+ };
208
+ const dep = toolMap[params.tool];
209
+ if (!dep) {
210
+ return createTextResult(`Unknown tool: ${params.tool}`);
211
+ }
212
+ const status = checkDependency(dep);
213
+ if (status.installed) {
214
+ return createTextResult(`${dep.name} is installed (version: ${status.version})`);
215
+ } else {
216
+ return createTextResult(`${dep.name} is NOT installed.
217
+ Install with: ${dep.installHint}`);
218
+ }
219
+ }
220
+ };
221
+ var setupInitTool = {
222
+ name: "dlab.setup.init",
223
+ description: "Initialize DiscoveryLab data directories and database.",
224
+ inputSchema: z.object({}),
225
+ handler: async () => {
226
+ try {
227
+ const { getDatabase, DATA_DIR: DATA_DIR2, PROJECTS_DIR, EXPORTS_DIR, FRAMES_DIR } = await import("./db-ADBEBNH6.js");
228
+ getDatabase();
229
+ return createJsonResult({
230
+ message: "DiscoveryLab initialized successfully",
231
+ directories: {
232
+ data: DATA_DIR2,
233
+ projects: PROJECTS_DIR,
234
+ exports: EXPORTS_DIR,
235
+ frames: FRAMES_DIR
236
+ }
237
+ });
238
+ } catch (error) {
239
+ const message = error instanceof Error ? error.message : "Initialization failed";
240
+ return createTextResult(`Error: ${message}`);
241
+ }
242
+ }
243
+ };
244
+ var setupInstallTool = {
245
+ name: "dlab.setup.install",
246
+ description: "Get installation commands for missing DiscoveryLab dependencies. Claude should run these commands after user approval.",
247
+ inputSchema: z.object({
248
+ tool: z.enum(["all", "ffmpeg", "maestro", "playwright", "xcode", "adb"]).optional().describe("Specific tool to install (default: all missing)")
249
+ }),
250
+ handler: async (params) => {
251
+ const toolToInstall = params.tool || "all";
252
+ const installCommands = [];
253
+ const isMac = platform() === "darwin";
254
+ if (toolToInstall === "all" || toolToInstall === "ffmpeg") {
255
+ const status = checkDependency(dependencies[0]);
256
+ if (!status.installed) {
257
+ installCommands.push({
258
+ name: "FFmpeg",
259
+ command: isMac ? "brew install ffmpeg" : "sudo apt install -y ffmpeg",
260
+ description: "Required for video processing and export"
261
+ });
262
+ }
263
+ }
264
+ if (toolToInstall === "all" || toolToInstall === "maestro") {
265
+ const status = checkDependency(dependencies[1]);
266
+ if (!status.installed) {
267
+ installCommands.push({
268
+ name: "Maestro CLI",
269
+ command: 'curl -Ls "https://get.maestro.mobile.dev" | bash',
270
+ description: "Mobile app testing automation"
271
+ });
272
+ }
273
+ }
274
+ if (toolToInstall === "all" || toolToInstall === "playwright") {
275
+ const status = checkDependency(dependencies[2]);
276
+ if (!status.installed) {
277
+ installCommands.push({
278
+ name: "Playwright",
279
+ command: "npm install -g playwright && npx playwright install",
280
+ description: "Web app testing and browser automation"
281
+ });
282
+ }
283
+ }
284
+ if (isMac && (toolToInstall === "all" || toolToInstall === "xcode")) {
285
+ const status = checkDependency(dependencies[3]);
286
+ if (!status.installed) {
287
+ installCommands.push({
288
+ name: "Xcode CLI Tools",
289
+ command: "xcode-select --install",
290
+ description: "Required for iOS Simulator access"
291
+ });
292
+ }
293
+ }
294
+ if (toolToInstall === "all" || toolToInstall === "adb") {
295
+ const status = checkDependency(dependencies[4]);
296
+ if (!status.installed) {
297
+ installCommands.push({
298
+ name: "ADB (Android Debug Bridge)",
299
+ command: isMac ? "brew install android-platform-tools" : "sudo apt install -y adb",
300
+ description: "Required for Android Emulator access"
301
+ });
302
+ }
303
+ }
304
+ if (installCommands.length === 0) {
305
+ return createTextResult(
306
+ toolToInstall === "all" ? "\u2705 All dependencies are already installed!" : `\u2705 ${toolToInstall} is already installed!`
307
+ );
308
+ }
309
+ const instructions = installCommands.map(
310
+ (cmd, i) => `${i + 1}. **${cmd.name}** (${cmd.description})
311
+ \`\`\`bash
312
+ ${cmd.command}
313
+ \`\`\``
314
+ ).join("\n\n");
315
+ return createTextResult(
316
+ `## Missing Dependencies
317
+
318
+ Please run the following commands to install missing dependencies:
319
+
320
+ ` + instructions + `
321
+
322
+ *Run these commands one at a time and verify each installation before proceeding.*`
323
+ );
324
+ }
325
+ };
326
+ var setupTools = [setupStatusTool, setupCheckTool, setupInitTool, setupInstallTool];
327
+
328
+ export {
329
+ setupStatusTool,
330
+ setupCheckTool,
331
+ setupInitTool,
332
+ setupInstallTool,
333
+ setupTools
334
+ };
@@ -0,0 +1,209 @@
1
+ import {
2
+ APP_VERSION
3
+ } from "./chunk-6EGBXRDK.js";
4
+
5
+ // src/mcp/server.ts
6
+ import { z } from "zod";
7
+ var MCPServer = class {
8
+ tools = /* @__PURE__ */ new Map();
9
+ serverInfo = {
10
+ name: "discoverylab",
11
+ version: APP_VERSION
12
+ };
13
+ registerTool(tool) {
14
+ this.tools.set(tool.name, tool);
15
+ }
16
+ registerTools(tools) {
17
+ for (const tool of tools) {
18
+ this.registerTool(tool);
19
+ }
20
+ }
21
+ async handleRequest(request) {
22
+ const { id, method, params } = request;
23
+ try {
24
+ switch (method) {
25
+ case "initialize":
26
+ return this.handleInitialize(id, params);
27
+ case "tools/list":
28
+ return this.handleToolsList(id);
29
+ case "tools/call":
30
+ return this.handleToolCall(id, params);
31
+ case "ping":
32
+ return { jsonrpc: "2.0", id, result: { pong: true } };
33
+ default:
34
+ return {
35
+ jsonrpc: "2.0",
36
+ id,
37
+ error: { code: -32601, message: `Method not found: ${method}` }
38
+ };
39
+ }
40
+ } catch (error) {
41
+ const message = error instanceof Error ? error.message : "Unknown error";
42
+ return {
43
+ jsonrpc: "2.0",
44
+ id,
45
+ error: { code: -32603, message }
46
+ };
47
+ }
48
+ }
49
+ handleInitialize(id, params) {
50
+ return {
51
+ jsonrpc: "2.0",
52
+ id,
53
+ result: {
54
+ protocolVersion: "2024-11-05",
55
+ serverInfo: this.serverInfo,
56
+ capabilities: {
57
+ tools: {}
58
+ }
59
+ }
60
+ };
61
+ }
62
+ handleToolsList(id) {
63
+ const tools = Array.from(this.tools.values()).map((tool) => ({
64
+ name: tool.name,
65
+ description: tool.description,
66
+ inputSchema: this.zodToJsonSchema(tool.inputSchema)
67
+ }));
68
+ return {
69
+ jsonrpc: "2.0",
70
+ id,
71
+ result: { tools }
72
+ };
73
+ }
74
+ async handleToolCall(id, params) {
75
+ const { name, arguments: args } = params;
76
+ const tool = this.tools.get(name);
77
+ if (!tool) {
78
+ return {
79
+ jsonrpc: "2.0",
80
+ id,
81
+ error: { code: -32602, message: `Tool not found: ${name}` }
82
+ };
83
+ }
84
+ try {
85
+ const validatedArgs = tool.inputSchema.parse(args || {});
86
+ const result = await tool.handler(validatedArgs);
87
+ return {
88
+ jsonrpc: "2.0",
89
+ id,
90
+ result
91
+ };
92
+ } catch (error) {
93
+ if (error instanceof z.ZodError) {
94
+ return {
95
+ jsonrpc: "2.0",
96
+ id,
97
+ error: {
98
+ code: -32602,
99
+ message: "Invalid parameters",
100
+ data: error.errors
101
+ }
102
+ };
103
+ }
104
+ const message = error instanceof Error ? error.message : "Tool execution failed";
105
+ return {
106
+ jsonrpc: "2.0",
107
+ id,
108
+ result: {
109
+ content: [{ type: "text", text: `Error: ${message}` }],
110
+ isError: true
111
+ }
112
+ };
113
+ }
114
+ }
115
+ zodToJsonSchema(schema) {
116
+ if (schema instanceof z.ZodObject) {
117
+ const shape = schema.shape;
118
+ const properties = {};
119
+ const required = [];
120
+ for (const [key, value] of Object.entries(shape)) {
121
+ properties[key] = this.zodToJsonSchema(value);
122
+ if (!value.isOptional()) {
123
+ required.push(key);
124
+ }
125
+ }
126
+ return {
127
+ type: "object",
128
+ properties,
129
+ required: required.length > 0 ? required : void 0
130
+ };
131
+ }
132
+ if (schema instanceof z.ZodString) {
133
+ return { type: "string" };
134
+ }
135
+ if (schema instanceof z.ZodNumber) {
136
+ return { type: "number" };
137
+ }
138
+ if (schema instanceof z.ZodBoolean) {
139
+ return { type: "boolean" };
140
+ }
141
+ if (schema instanceof z.ZodArray) {
142
+ return {
143
+ type: "array",
144
+ items: this.zodToJsonSchema(schema.element)
145
+ };
146
+ }
147
+ if (schema instanceof z.ZodOptional) {
148
+ return this.zodToJsonSchema(schema.unwrap());
149
+ }
150
+ if (schema instanceof z.ZodEnum) {
151
+ return {
152
+ type: "string",
153
+ enum: schema.options
154
+ };
155
+ }
156
+ return { type: "object" };
157
+ }
158
+ // STDIO transport
159
+ async runStdio() {
160
+ const readline = await import("readline");
161
+ const rl = readline.createInterface({
162
+ input: process.stdin,
163
+ output: process.stdout,
164
+ terminal: false
165
+ });
166
+ rl.on("line", async (line) => {
167
+ try {
168
+ const request = JSON.parse(line);
169
+ const response = await this.handleRequest(request);
170
+ console.log(JSON.stringify(response));
171
+ } catch (error) {
172
+ const errorResponse = {
173
+ jsonrpc: "2.0",
174
+ id: 0,
175
+ error: { code: -32700, message: "Parse error" }
176
+ };
177
+ console.log(JSON.stringify(errorResponse));
178
+ }
179
+ });
180
+ rl.on("close", () => {
181
+ process.exit(0);
182
+ });
183
+ }
184
+ };
185
+ function createTextResult(text) {
186
+ return {
187
+ content: [{ type: "text", text }]
188
+ };
189
+ }
190
+ function createErrorResult(message) {
191
+ return {
192
+ content: [{ type: "text", text: `Error: ${message}` }],
193
+ isError: true
194
+ };
195
+ }
196
+ function createJsonResult(data) {
197
+ return {
198
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
199
+ };
200
+ }
201
+ var mcpServer = new MCPServer();
202
+
203
+ export {
204
+ MCPServer,
205
+ createTextResult,
206
+ createErrorResult,
207
+ createJsonResult,
208
+ mcpServer
209
+ };