@rootnative/loupe 0.0.0-alpha.0 → 0.0.0-alpha.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.
- package/CHANGELOG.md +45 -0
- package/README.md +187 -4
- package/dist/bin.js +315 -0
- package/dist/chunk-HWVQXYQ3.js +7161 -0
- package/dist/index.d.ts +222 -0
- package/dist/index.js +42 -0
- package/dist/server-567FSCAH.js +211 -0
- package/package.json +40 -1
- package/skills/loupe/SKILL.md +186 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const version: string;
|
|
4
|
+
|
|
5
|
+
/** Every loupe command. The CLI is made from this list. */
|
|
6
|
+
declare const registry: Registry;
|
|
7
|
+
|
|
8
|
+
interface ExecOptions {
|
|
9
|
+
/** Milliseconds before loupe stops the tool. Default: 30 000. */
|
|
10
|
+
timeout?: number;
|
|
11
|
+
}
|
|
12
|
+
interface ExecResult {
|
|
13
|
+
/** The exit code, or `null` when a signal stopped the tool. */
|
|
14
|
+
code: number | null;
|
|
15
|
+
/** Raw bytes, because a tool can write binary data, for example a PNG. */
|
|
16
|
+
stdout: Buffer;
|
|
17
|
+
stderr: Buffer;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Runs a tool with no shell, so no argument goes through shell parsing. It
|
|
21
|
+
* fails with `tool_missing` when the tool doesn't exist, and with `timeout`
|
|
22
|
+
* when the tool runs too long. A non-zero exit code isn't a failure here:
|
|
23
|
+
* the caller decides what it means.
|
|
24
|
+
*/
|
|
25
|
+
type Exec = (file: string, args: readonly string[], options?: ExecOptions) => Promise<ExecResult>;
|
|
26
|
+
|
|
27
|
+
/** How far a long command is. `progress` grows with each update. */
|
|
28
|
+
interface ProgressUpdate {
|
|
29
|
+
progress: number;
|
|
30
|
+
total?: number;
|
|
31
|
+
message?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Everything a command takes from the machine it runs on. A test passes a
|
|
35
|
+
* fake context that replays recorded tool output.
|
|
36
|
+
*/
|
|
37
|
+
interface CommandContext {
|
|
38
|
+
exec: Exec;
|
|
39
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
40
|
+
/**
|
|
41
|
+
* HTTP to a server on this machine, such as Metro. `createContext` gives
|
|
42
|
+
* `localFetch`, which refuses every other host.
|
|
43
|
+
*/
|
|
44
|
+
fetch: typeof fetch;
|
|
45
|
+
/**
|
|
46
|
+
* Aborts when the caller cancels the call: Ctrl-C in the CLI, or a
|
|
47
|
+
* cancel from the MCP client. A long command stops at its next safe
|
|
48
|
+
* point; a tool that runs isn't stopped.
|
|
49
|
+
*/
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
/** Takes the progress of a long command, for the caller to show. */
|
|
52
|
+
progress?: (update: ProgressUpdate) => void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The real context: child processes, the environment of this process, and
|
|
56
|
+
* HTTP to this machine.
|
|
57
|
+
*/
|
|
58
|
+
declare function createContext(): CommandContext;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* One command, defined once. The CLI and the MCP server are both made from
|
|
62
|
+
* this definition, so the two can't drift apart.
|
|
63
|
+
*/
|
|
64
|
+
interface Command<I extends z.ZodObject = z.ZodObject, O extends z.ZodType = z.ZodType> {
|
|
65
|
+
/** Kebab case, for example `open-url`. */
|
|
66
|
+
name: string;
|
|
67
|
+
/** One line for the help text and the MCP tool description. */
|
|
68
|
+
summary: string;
|
|
69
|
+
input: I;
|
|
70
|
+
output: O;
|
|
71
|
+
/**
|
|
72
|
+
* Input fields that the CLI also takes by position, in order:
|
|
73
|
+
* `open-url <url>`. Each one still works as a flag.
|
|
74
|
+
*/
|
|
75
|
+
positionals?: readonly (keyof z.output<I> & string)[];
|
|
76
|
+
/**
|
|
77
|
+
* The command changes nothing on the device, and it writes a file only
|
|
78
|
+
* where its input names one. An MCP client can run such a tool with no
|
|
79
|
+
* prompt.
|
|
80
|
+
*/
|
|
81
|
+
readOnly?: boolean;
|
|
82
|
+
run(input: z.output<I>, context: CommandContext): Promise<z.input<O>> | z.input<O>;
|
|
83
|
+
/** A short summary for a person at a terminal. JSON is the default. */
|
|
84
|
+
format?(data: z.output<O>): string;
|
|
85
|
+
/**
|
|
86
|
+
* The PNG files of the result that an agent should see. The MCP result
|
|
87
|
+
* also holds each one as an image block; the CLI gives only the paths.
|
|
88
|
+
*/
|
|
89
|
+
images?(data: z.output<O>): string[];
|
|
90
|
+
/**
|
|
91
|
+
* For a command that checks something: false when the check failed. The
|
|
92
|
+
* result is still a success with all its data, and the CLI exits 1.
|
|
93
|
+
*/
|
|
94
|
+
passed?(data: z.output<O>): boolean;
|
|
95
|
+
}
|
|
96
|
+
declare function defineCommand<I extends z.ZodObject, O extends z.ZodType>(command: Command<I, O>): Command<I, O>;
|
|
97
|
+
interface Registry {
|
|
98
|
+
list(): readonly Command[];
|
|
99
|
+
get(name: string): Command | undefined;
|
|
100
|
+
}
|
|
101
|
+
declare function createRegistry(commands: readonly Command[]): Registry;
|
|
102
|
+
|
|
103
|
+
declare const deviceSchema: z.ZodObject<{
|
|
104
|
+
platform: z.ZodEnum<{
|
|
105
|
+
android: "android";
|
|
106
|
+
}>;
|
|
107
|
+
kind: z.ZodEnum<{
|
|
108
|
+
emulator: "emulator";
|
|
109
|
+
device: "device";
|
|
110
|
+
}>;
|
|
111
|
+
serial: z.ZodOptional<z.ZodString>;
|
|
112
|
+
avd: z.ZodOptional<z.ZodString>;
|
|
113
|
+
model: z.ZodOptional<z.ZodString>;
|
|
114
|
+
state: z.ZodEnum<{
|
|
115
|
+
ready: "ready";
|
|
116
|
+
booting: "booting";
|
|
117
|
+
stopped: "stopped";
|
|
118
|
+
offline: "offline";
|
|
119
|
+
unauthorized: "unauthorized";
|
|
120
|
+
"no-permissions": "no-permissions";
|
|
121
|
+
other: "other";
|
|
122
|
+
}>;
|
|
123
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
124
|
+
apiLevel: z.ZodOptional<z.ZodNumber>;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
type Device = z.infer<typeof deviceSchema>;
|
|
127
|
+
type DeviceState = Device['state'];
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* In the order of the rotation: each step turns the device a quarter turn
|
|
131
|
+
* to the left (counter-clockwise), as Android counts `Surface.ROTATION_*`.
|
|
132
|
+
*/
|
|
133
|
+
declare const ORIENTATIONS: readonly ["portrait", "landscape-left", "portrait-upside-down", "landscape-right"];
|
|
134
|
+
type Orientation = (typeof ORIENTATIONS)[number];
|
|
135
|
+
declare const displaySchema: z.ZodObject<{
|
|
136
|
+
orientation: z.ZodEnum<{
|
|
137
|
+
portrait: "portrait";
|
|
138
|
+
"landscape-left": "landscape-left";
|
|
139
|
+
"portrait-upside-down": "portrait-upside-down";
|
|
140
|
+
"landscape-right": "landscape-right";
|
|
141
|
+
}>;
|
|
142
|
+
size: z.ZodObject<{
|
|
143
|
+
width: z.ZodNumber;
|
|
144
|
+
height: z.ZodNumber;
|
|
145
|
+
}, z.core.$strip>;
|
|
146
|
+
pixels: z.ZodObject<{
|
|
147
|
+
width: z.ZodNumber;
|
|
148
|
+
height: z.ZodNumber;
|
|
149
|
+
}, z.core.$strip>;
|
|
150
|
+
scale: z.ZodNumber;
|
|
151
|
+
}, z.core.$strip>;
|
|
152
|
+
type DisplayState = z.infer<typeof displaySchema>;
|
|
153
|
+
|
|
154
|
+
declare const ERROR_CODES: readonly ["unknown_command", "invalid_input", "invalid_output", "tool_missing", "tool_failed", "timeout", "no_device", "device_ambiguous", "device_unavailable", "unsupported", "orientation_locked", "app_not_in_front", "not_idle", "element_not_found", "element_ambiguous", "no_handler", "no_server", "cancelled", "internal"];
|
|
155
|
+
type ErrorCode = (typeof ERROR_CODES)[number];
|
|
156
|
+
/** An error that a caller can act on by its code. */
|
|
157
|
+
declare class LoupeError extends Error {
|
|
158
|
+
readonly code: ErrorCode;
|
|
159
|
+
constructor(code: ErrorCode, message: string, options?: ErrorOptions);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
interface CommandSuccess<T = unknown> {
|
|
163
|
+
ok: true;
|
|
164
|
+
command: string;
|
|
165
|
+
data: T;
|
|
166
|
+
}
|
|
167
|
+
interface CommandFailure {
|
|
168
|
+
ok: false;
|
|
169
|
+
command: string;
|
|
170
|
+
error: {
|
|
171
|
+
code: ErrorCode;
|
|
172
|
+
message: string;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
type CommandResult<T = unknown> = CommandSuccess<T> | CommandFailure;
|
|
176
|
+
/**
|
|
177
|
+
* Checks the input, runs the command, and checks the output. It never
|
|
178
|
+
* throws: each problem comes back as a failure with a code.
|
|
179
|
+
*/
|
|
180
|
+
declare function runCommand(registry: Registry, name: string, input: unknown, context?: CommandContext): Promise<CommandResult>;
|
|
181
|
+
|
|
182
|
+
type Platform = 'ios' | 'android';
|
|
183
|
+
/** Device points: pt on iOS, dp on Android. */
|
|
184
|
+
type Unit = 'pt' | 'dp';
|
|
185
|
+
interface Point {
|
|
186
|
+
x: number;
|
|
187
|
+
y: number;
|
|
188
|
+
}
|
|
189
|
+
interface Size {
|
|
190
|
+
width: number;
|
|
191
|
+
height: number;
|
|
192
|
+
}
|
|
193
|
+
/** The origin is the top-left corner of the current orientation. */
|
|
194
|
+
interface Rect extends Point, Size {
|
|
195
|
+
}
|
|
196
|
+
interface Insets {
|
|
197
|
+
top: number;
|
|
198
|
+
right: number;
|
|
199
|
+
bottom: number;
|
|
200
|
+
left: number;
|
|
201
|
+
}
|
|
202
|
+
declare function unitOf(platform: Platform): Unit;
|
|
203
|
+
/** Pixels are whole numbers, so the result is rounded. */
|
|
204
|
+
declare function toPixels(value: number, scale: number): number;
|
|
205
|
+
/** Not rounded: 1080 px at scale 2.625 is 411.43 dp, and a check needs it. */
|
|
206
|
+
declare function fromPixels(pixels: number, scale: number): number;
|
|
207
|
+
declare function pointToPixels(point: Point, scale: number): Point;
|
|
208
|
+
declare function rectFromPixels(rect: Rect, scale: number): Rect;
|
|
209
|
+
declare function rectRight(rect: Rect): number;
|
|
210
|
+
declare function rectBottom(rect: Rect): number;
|
|
211
|
+
declare function rectCentre(rect: Rect): Point;
|
|
212
|
+
/**
|
|
213
|
+
* True when `inner` is fully inside `outer`. `tolerance` lets `inner` run
|
|
214
|
+
* past each edge by that much, for sub-pixel rounding.
|
|
215
|
+
*/
|
|
216
|
+
declare function containsRect(outer: Rect, inner: Rect, tolerance?: number): boolean;
|
|
217
|
+
/** The shared area of two rects, or null when they only touch or are apart. */
|
|
218
|
+
declare function intersection(a: Rect, b: Rect): Rect | null;
|
|
219
|
+
/** The safe area: the screen with its insets removed. */
|
|
220
|
+
declare function insetRect(screen: Size, insets: Insets): Rect;
|
|
221
|
+
|
|
222
|
+
export { type Command, type CommandContext, type CommandFailure, type CommandResult, type CommandSuccess, type Device, type DeviceState, type DisplayState, ERROR_CODES, type ErrorCode, type Exec, type ExecOptions, type ExecResult, type Insets, LoupeError, type Orientation, type Platform, type Point, type Rect, type Registry, type Size, type Unit, containsRect, createContext, createRegistry, defineCommand, fromPixels, insetRect, intersection, pointToPixels, rectBottom, rectCentre, rectFromPixels, rectRight, registry, runCommand, toPixels, unitOf, version };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ERROR_CODES,
|
|
3
|
+
LoupeError,
|
|
4
|
+
containsRect,
|
|
5
|
+
createContext,
|
|
6
|
+
createRegistry,
|
|
7
|
+
defineCommand,
|
|
8
|
+
fromPixels,
|
|
9
|
+
insetRect,
|
|
10
|
+
intersection,
|
|
11
|
+
pointToPixels,
|
|
12
|
+
rectBottom,
|
|
13
|
+
rectCentre,
|
|
14
|
+
rectFromPixels,
|
|
15
|
+
rectRight,
|
|
16
|
+
registry,
|
|
17
|
+
runCommand,
|
|
18
|
+
toPixels,
|
|
19
|
+
unitOf,
|
|
20
|
+
version
|
|
21
|
+
} from "./chunk-HWVQXYQ3.js";
|
|
22
|
+
export {
|
|
23
|
+
ERROR_CODES,
|
|
24
|
+
LoupeError,
|
|
25
|
+
containsRect,
|
|
26
|
+
createContext,
|
|
27
|
+
createRegistry,
|
|
28
|
+
defineCommand,
|
|
29
|
+
fromPixels,
|
|
30
|
+
insetRect,
|
|
31
|
+
intersection,
|
|
32
|
+
pointToPixels,
|
|
33
|
+
rectBottom,
|
|
34
|
+
rectCentre,
|
|
35
|
+
rectFromPixels,
|
|
36
|
+
rectRight,
|
|
37
|
+
registry,
|
|
38
|
+
runCommand,
|
|
39
|
+
toPixels,
|
|
40
|
+
unitOf,
|
|
41
|
+
version
|
|
42
|
+
};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
inputJsonSchema,
|
|
4
|
+
outputJsonSchema,
|
|
5
|
+
registry,
|
|
6
|
+
round2,
|
|
7
|
+
runCommand,
|
|
8
|
+
version
|
|
9
|
+
} from "./chunk-HWVQXYQ3.js";
|
|
10
|
+
|
|
11
|
+
// src/mcp/server.ts
|
|
12
|
+
import { existsSync } from "fs";
|
|
13
|
+
import path from "path";
|
|
14
|
+
import { fileURLToPath } from "url";
|
|
15
|
+
import {
|
|
16
|
+
McpServer,
|
|
17
|
+
ProtocolError,
|
|
18
|
+
ProtocolErrorCode
|
|
19
|
+
} from "@modelcontextprotocol/server";
|
|
20
|
+
import { loadSkills } from "@modelcontextprotocol/server/ext/skills/node";
|
|
21
|
+
import {
|
|
22
|
+
serveStdio,
|
|
23
|
+
StdioServerTransport
|
|
24
|
+
} from "@modelcontextprotocol/server/stdio";
|
|
25
|
+
|
|
26
|
+
// src/mcp/tools.ts
|
|
27
|
+
import { readFile } from "fs/promises";
|
|
28
|
+
var IMAGE_LIMIT = 375e4;
|
|
29
|
+
function megabytes(bytes) {
|
|
30
|
+
return `${round2(bytes / 1e6)} MB`;
|
|
31
|
+
}
|
|
32
|
+
async function imageBlocks(files, limit = IMAGE_LIMIT) {
|
|
33
|
+
return Promise.all(
|
|
34
|
+
files.map(async (file) => {
|
|
35
|
+
let png;
|
|
36
|
+
try {
|
|
37
|
+
png = await readFile(file);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
40
|
+
return {
|
|
41
|
+
type: "text",
|
|
42
|
+
text: `loupe can't read ${file} to show it: ${why}`
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (png.length > limit) {
|
|
46
|
+
return {
|
|
47
|
+
type: "text",
|
|
48
|
+
text: `loupe left the image of ${file} out of this result: the PNG has ${megabytes(png.length)}, and an image block takes ${megabytes(limit)} at most. Open the file, or make the image smaller: a screenshot with a scale (for example 0.5) or a crop, or a sweep of fewer links.`
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
type: "image",
|
|
53
|
+
data: png.toString("base64"),
|
|
54
|
+
mimeType: "image/png"
|
|
55
|
+
};
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
function toolSchema(command, side, schema) {
|
|
60
|
+
const copy = { ...schema };
|
|
61
|
+
delete copy.$schema;
|
|
62
|
+
if (copy.type !== "object") {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`${command.name}: the ${side} must be an object to be an MCP tool.`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
return copy;
|
|
68
|
+
}
|
|
69
|
+
function toolOf(command) {
|
|
70
|
+
return {
|
|
71
|
+
name: command.name,
|
|
72
|
+
description: command.summary,
|
|
73
|
+
inputSchema: toolSchema(command, "input", inputJsonSchema(command)),
|
|
74
|
+
outputSchema: toolSchema(command, "output", outputJsonSchema(command)),
|
|
75
|
+
annotations: { readOnlyHint: command.readOnly === true }
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function toolsOf(registry2) {
|
|
79
|
+
return registry2.list().map(toolOf);
|
|
80
|
+
}
|
|
81
|
+
function isJsonObject(value) {
|
|
82
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
83
|
+
}
|
|
84
|
+
function toolResult(result) {
|
|
85
|
+
if (!result.ok) {
|
|
86
|
+
return {
|
|
87
|
+
content: [
|
|
88
|
+
{ type: "text", text: JSON.stringify({ error: result.error }) }
|
|
89
|
+
],
|
|
90
|
+
isError: true
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const text = JSON.stringify(result.data);
|
|
94
|
+
const data = JSON.parse(text);
|
|
95
|
+
return {
|
|
96
|
+
content: [{ type: "text", text }],
|
|
97
|
+
...isJsonObject(data) && { structuredContent: data }
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/mcp/server.ts
|
|
102
|
+
var INSTRUCTIONS = [
|
|
103
|
+
"loupe checks the layout of a mobile app on an Android emulator or device. Its tools give numbers in dp.",
|
|
104
|
+
"Ask the user before you start an emulator, and before you open an app or a link on a device.",
|
|
105
|
+
"On a real phone, give `app` in each call.",
|
|
106
|
+
"Put back what you change: the orientation, the theme, and RTL (`expo-rtl off`). A sweep puts back the orientation and the theme itself.",
|
|
107
|
+
"Decide pass or fail with `check` or `sweep`, not from a screenshot alone.",
|
|
108
|
+
"The loupe skill (skills/loupe/SKILL.md in the package) has the workflow, the rules, and what to do for each error code."
|
|
109
|
+
].join(" ");
|
|
110
|
+
function serial() {
|
|
111
|
+
let last = Promise.resolve();
|
|
112
|
+
return (task) => {
|
|
113
|
+
const next = last.then(task);
|
|
114
|
+
last = next.catch(() => void 0);
|
|
115
|
+
return next;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function skillsFolder() {
|
|
119
|
+
let dir = path.dirname(fileURLToPath(import.meta.url));
|
|
120
|
+
for (; ; ) {
|
|
121
|
+
if (existsSync(path.join(dir, "package.json"))) {
|
|
122
|
+
return path.join(dir, "skills");
|
|
123
|
+
}
|
|
124
|
+
const up = path.dirname(dir);
|
|
125
|
+
if (up === dir) throw new Error("loupe can't find its package folder.");
|
|
126
|
+
dir = up;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function createMcpServer(registry2, context, { oneAtATime = serial(), skills } = {}) {
|
|
130
|
+
const tools = toolsOf(registry2);
|
|
131
|
+
const byName = new Map(tools.map((tool) => [tool.name, tool]));
|
|
132
|
+
const mcp = new McpServer(
|
|
133
|
+
{ name: "loupe", version },
|
|
134
|
+
{ instructions: INSTRUCTIONS }
|
|
135
|
+
);
|
|
136
|
+
const { server } = mcp;
|
|
137
|
+
server.registerCapabilities({ tools: {} });
|
|
138
|
+
server.setRequestHandler("tools/list", () => ({ tools }));
|
|
139
|
+
server.setRequestHandler("tools/call", async (request, ctx) => {
|
|
140
|
+
const { name, arguments: input = {} } = request.params;
|
|
141
|
+
const tool = byName.get(name);
|
|
142
|
+
if (!tool) {
|
|
143
|
+
throw new ProtocolError(
|
|
144
|
+
ProtocolErrorCode.InvalidParams,
|
|
145
|
+
`"${name}" is not a loupe tool.`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
const token = ctx.mcpReq._meta?.progressToken;
|
|
149
|
+
const call = {
|
|
150
|
+
...context,
|
|
151
|
+
signal: ctx.mcpReq.signal,
|
|
152
|
+
...token !== void 0 && {
|
|
153
|
+
progress: (update) => {
|
|
154
|
+
ctx.mcpReq.notify({
|
|
155
|
+
method: "notifications/progress",
|
|
156
|
+
params: { progressToken: token, ...update }
|
|
157
|
+
}).catch(() => void 0);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const output = await oneAtATime(async () => {
|
|
162
|
+
const result = await runCommand(registry2, name, input, call);
|
|
163
|
+
const shown = toolResult(result);
|
|
164
|
+
const images = result.ok && registry2.get(name)?.images?.(result.data);
|
|
165
|
+
if (images) shown.content.push(...await imageBlocks(images));
|
|
166
|
+
return shown;
|
|
167
|
+
});
|
|
168
|
+
return server.projectCallToolResult(output, tool.outputSchema);
|
|
169
|
+
});
|
|
170
|
+
skills?.attach(mcp);
|
|
171
|
+
return mcp;
|
|
172
|
+
}
|
|
173
|
+
async function serveMcp(options = {}) {
|
|
174
|
+
const {
|
|
175
|
+
registry: registry2 = registry,
|
|
176
|
+
context = createContext(),
|
|
177
|
+
stdin = process.stdin,
|
|
178
|
+
stdout = process.stdout,
|
|
179
|
+
onerror
|
|
180
|
+
} = options;
|
|
181
|
+
const oneAtATime = serial();
|
|
182
|
+
const ended = new Promise((resolve) => stdin.once("end", resolve));
|
|
183
|
+
const skills = await loadSkills(skillsFolder(), {
|
|
184
|
+
onWarning: ({ path: file, message }) => onerror?.(new Error(`The skill at ${file}: ${message}`))
|
|
185
|
+
}).catch((error) => {
|
|
186
|
+
onerror?.(
|
|
187
|
+
new Error(
|
|
188
|
+
`loupe serves no skill: ${error instanceof Error ? error.message : String(error)}`
|
|
189
|
+
)
|
|
190
|
+
);
|
|
191
|
+
return void 0;
|
|
192
|
+
});
|
|
193
|
+
const closed = new Promise((resolve) => {
|
|
194
|
+
serveStdio(
|
|
195
|
+
() => {
|
|
196
|
+
const mcp = createMcpServer(registry2, context, { oneAtATime, skills });
|
|
197
|
+
mcp.server.onclose = resolve;
|
|
198
|
+
return mcp;
|
|
199
|
+
},
|
|
200
|
+
{ transport: new StdioServerTransport(stdin, stdout), onerror }
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
await Promise.race([ended, closed]);
|
|
204
|
+
}
|
|
205
|
+
export {
|
|
206
|
+
INSTRUCTIONS,
|
|
207
|
+
createMcpServer,
|
|
208
|
+
serial,
|
|
209
|
+
serveMcp,
|
|
210
|
+
skillsFolder
|
|
211
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rootnative/loupe",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.2",
|
|
4
4
|
"description": "loupe by Root Native: layout checks for iOS and Android, built for AI agents. Drive simulators and emulators, and measure every screen to the point.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Root Native",
|
|
@@ -25,11 +25,50 @@
|
|
|
25
25
|
"ai-agents",
|
|
26
26
|
"cli"
|
|
27
27
|
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"bin": {
|
|
32
|
+
"loupe": "./dist/bin.js"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
"./package.json": "./package.json",
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
28
41
|
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"skills",
|
|
29
44
|
"README.md",
|
|
45
|
+
"CHANGELOG.md",
|
|
30
46
|
"LICENSE"
|
|
31
47
|
],
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=20.19"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsup",
|
|
53
|
+
"prepack": "turbo run build --filter=@rootnative/loupe",
|
|
54
|
+
"dev": "tsup --watch",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"lint": "eslint . --max-warnings 0",
|
|
58
|
+
"clean": "node -e \"for (const p of ['dist', '.turbo']) require('node:fs').rmSync(p, { recursive: true, force: true })\""
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@modelcontextprotocol/client": "^2.4.0",
|
|
62
|
+
"@types/node": "^22.20.2",
|
|
63
|
+
"tsup": "^8.5.1",
|
|
64
|
+
"typescript": "^5.9.3",
|
|
65
|
+
"vitest": "^3.2.4"
|
|
66
|
+
},
|
|
32
67
|
"publishConfig": {
|
|
33
68
|
"access": "public"
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
72
|
+
"zod": "^4.6.7"
|
|
34
73
|
}
|
|
35
74
|
}
|