@reticlehq/core 1.3.0
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/LICENSE +113 -0
- package/README.md +97 -0
- package/dist/babel.d.ts +7 -0
- package/dist/babel.js +32 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +11264 -0
- package/dist/eslint.d.ts +1 -0
- package/dist/eslint.js +134 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5543 -0
- package/dist/loader.cjs +52 -0
- package/dist/next.d.ts +21 -0
- package/dist/next.js +24 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +9486 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +9368 -0
- package/dist/vite.d.ts +1 -0
- package/dist/vite.js +196 -0
- package/package.json +98 -0
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ReticleVitePlugin, ReticleVitePluginOptions, reticle } from '@reticlehq/vite-plugin';
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// ../vite-plugin/dist/index.js
|
|
2
|
+
import { transformSync } from "@babel/core";
|
|
3
|
+
|
|
4
|
+
// ../babel-plugin/dist/index.js
|
|
5
|
+
import { relative } from "path";
|
|
6
|
+
var SOURCE_ATTR = "data-reticle-source";
|
|
7
|
+
function reticleSourcePlugin({ types: t }) {
|
|
8
|
+
return {
|
|
9
|
+
name: "reticle-source",
|
|
10
|
+
visitor: {
|
|
11
|
+
JSXOpeningElement(path, state) {
|
|
12
|
+
const node = path.node;
|
|
13
|
+
if (node.name.type !== "JSXIdentifier")
|
|
14
|
+
return;
|
|
15
|
+
const first = node.name.name[0];
|
|
16
|
+
if (first === void 0 || first !== first.toLowerCase())
|
|
17
|
+
return;
|
|
18
|
+
const alreadyStamped = node.attributes.some((attr) => attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === SOURCE_ATTR);
|
|
19
|
+
if (alreadyStamped)
|
|
20
|
+
return;
|
|
21
|
+
const loc = node.loc;
|
|
22
|
+
if (loc === null || loc === void 0)
|
|
23
|
+
return;
|
|
24
|
+
const filename = state.filename ?? "unknown";
|
|
25
|
+
const rel = relative(process.cwd(), filename);
|
|
26
|
+
const value = `${rel}:${String(loc.start.line)}:${String(loc.start.column)}`;
|
|
27
|
+
node.attributes.push(t.jsxAttribute(t.jsxIdentifier(SOURCE_ATTR), t.stringLiteral(value)));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ../protocol/dist/constants.js
|
|
34
|
+
var RETICLE_DEFAULT_PORT = 4400;
|
|
35
|
+
var RETICLE_WS_PATH = "/reticle";
|
|
36
|
+
var TRANSPORT_LIMITS = {
|
|
37
|
+
MAX_MESSAGE_BYTES: 1024 * 1024,
|
|
38
|
+
MAX_MESSAGES_PER_SECOND: 1e3,
|
|
39
|
+
MAX_SESSIONS: 32,
|
|
40
|
+
MAX_PENDING_CONNECTIONS: 16,
|
|
41
|
+
HELLO_TIMEOUT_MS: 5e3,
|
|
42
|
+
MAX_BUFFER_BYTES: 8 * 1024 * 1024,
|
|
43
|
+
MAX_SESSION_ID_LENGTH: 128,
|
|
44
|
+
MAX_URL_LENGTH: 4096,
|
|
45
|
+
MAX_TITLE_LENGTH: 512,
|
|
46
|
+
MAX_ADAPTERS: 32,
|
|
47
|
+
MAX_ADAPTER_NAME_LENGTH: 128,
|
|
48
|
+
MAX_TOKEN_LENGTH: 512,
|
|
49
|
+
MAX_COMMAND_ID_LENGTH: 128,
|
|
50
|
+
MAX_COMMAND_NAME_LENGTH: 128,
|
|
51
|
+
MAX_REF_LENGTH: 128,
|
|
52
|
+
MAX_ERROR_LENGTH: 4096,
|
|
53
|
+
MAX_SERIALIZE_DEPTH: 8,
|
|
54
|
+
MAX_COLLECTION_ITEMS: 200,
|
|
55
|
+
MAX_OBJECT_KEYS: 200,
|
|
56
|
+
MAX_STRING_LENGTH: 64 * 1024,
|
|
57
|
+
/** Human review marks: the note the human types when flagging a mistake on the page. */
|
|
58
|
+
MAX_MARK_NOTE_LENGTH: 2e3,
|
|
59
|
+
/** Human review marks: the legible element label that pins the mark (e.g. "Submit button"). */
|
|
60
|
+
MAX_MARK_LABEL_LENGTH: 256
|
|
61
|
+
};
|
|
62
|
+
var UpdateCheckIntervalMs = 24 * 60 * 60 * 1e3;
|
|
63
|
+
var RING_BUFFER_DEFAULTS = {
|
|
64
|
+
MAX_EVENTS: 2e3,
|
|
65
|
+
MAX_AGE_MS: 6e4,
|
|
66
|
+
MAX_BYTES: TRANSPORT_LIMITS.MAX_BUFFER_BYTES
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// ../vite-plugin/dist/project-id.js
|
|
70
|
+
import { createHash } from "crypto";
|
|
71
|
+
import { basename, dirname, join } from "path";
|
|
72
|
+
import { existsSync, readFileSync } from "fs";
|
|
73
|
+
function slugifyPackageName(name) {
|
|
74
|
+
return name.toLowerCase().replace(/^@/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
75
|
+
}
|
|
76
|
+
function shortHash(input) {
|
|
77
|
+
return createHash("sha1").update(input).digest("hex").slice(0, 8);
|
|
78
|
+
}
|
|
79
|
+
function deriveProjectId(pkgName, rootPath) {
|
|
80
|
+
const fromName = pkgName !== void 0 ? slugifyPackageName(pkgName) : "";
|
|
81
|
+
const base = fromName.length > 0 ? fromName : slugifyPackageName(basename(rootPath)) || "app";
|
|
82
|
+
return `${base}-${shortHash(rootPath)}`;
|
|
83
|
+
}
|
|
84
|
+
function readNearestPackageName(startDir) {
|
|
85
|
+
let dir = startDir;
|
|
86
|
+
for (let depth = 0; depth < 50; depth++) {
|
|
87
|
+
const pkgPath = join(dir, "package.json");
|
|
88
|
+
if (existsSync(pkgPath)) {
|
|
89
|
+
try {
|
|
90
|
+
const parsed = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
91
|
+
if (typeof parsed === "object" && parsed !== null) {
|
|
92
|
+
const name = parsed["name"];
|
|
93
|
+
if (typeof name === "string" && name.length > 0)
|
|
94
|
+
return name;
|
|
95
|
+
}
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const parent = dirname(dir);
|
|
100
|
+
if (parent === dir)
|
|
101
|
+
break;
|
|
102
|
+
dir = parent;
|
|
103
|
+
}
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
function resolveProjectId(explicit, cwd, readPkgName = readNearestPackageName) {
|
|
107
|
+
if (explicit !== void 0 && explicit.length > 0)
|
|
108
|
+
return explicit;
|
|
109
|
+
return deriveProjectId(readPkgName(cwd), cwd);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ../vite-plugin/dist/index.js
|
|
113
|
+
var RETICLE_VITE_PLUGIN_NAME = "reticle";
|
|
114
|
+
var RETICLE_PACKAGE = "@reticlehq/core";
|
|
115
|
+
var JSX_FILE = /\.[jt]sx$/;
|
|
116
|
+
var VIRTUAL_PREFIX = "\0";
|
|
117
|
+
var NODE_MODULES = "node_modules";
|
|
118
|
+
var RETICLE_CONNECT_MODULE = "/@reticle-connect";
|
|
119
|
+
function shouldStamp(id) {
|
|
120
|
+
if (id.startsWith(VIRTUAL_PREFIX))
|
|
121
|
+
return false;
|
|
122
|
+
if (id.includes(NODE_MODULES))
|
|
123
|
+
return false;
|
|
124
|
+
const clean = id.split("?")[0] ?? id;
|
|
125
|
+
return JSX_FILE.test(clean);
|
|
126
|
+
}
|
|
127
|
+
function stamp(code, id) {
|
|
128
|
+
const out = transformSync(code, {
|
|
129
|
+
filename: id,
|
|
130
|
+
plugins: [reticleSourcePlugin],
|
|
131
|
+
parserOpts: { plugins: ["jsx", "typescript"] },
|
|
132
|
+
sourceMaps: true,
|
|
133
|
+
configFile: false,
|
|
134
|
+
babelrc: false
|
|
135
|
+
});
|
|
136
|
+
if (out?.code === void 0 || out.code === null)
|
|
137
|
+
return null;
|
|
138
|
+
return {
|
|
139
|
+
code: out.code,
|
|
140
|
+
map: out.map === void 0 || out.map === null ? null : JSON.stringify(out.map)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function connectArgs(options) {
|
|
144
|
+
const args = {};
|
|
145
|
+
const port = options.port ?? RETICLE_DEFAULT_PORT;
|
|
146
|
+
if (port !== RETICLE_DEFAULT_PORT)
|
|
147
|
+
args["url"] = `ws://localhost:${String(port)}${RETICLE_WS_PATH}`;
|
|
148
|
+
if (options.session !== void 0)
|
|
149
|
+
args["session"] = options.session;
|
|
150
|
+
if (options.projectId !== void 0)
|
|
151
|
+
args["projectId"] = options.projectId;
|
|
152
|
+
if (options.token !== void 0)
|
|
153
|
+
args["token"] = options.token;
|
|
154
|
+
return Object.keys(args).length > 0 ? JSON.stringify(args) : "";
|
|
155
|
+
}
|
|
156
|
+
function connectModuleSource(options) {
|
|
157
|
+
const args = connectArgs(options);
|
|
158
|
+
return `import { reticle, install } from '${RETICLE_PACKAGE}';
|
|
159
|
+
install();
|
|
160
|
+
reticle.connect(${args});
|
|
161
|
+
`;
|
|
162
|
+
}
|
|
163
|
+
function reticle(options = {}) {
|
|
164
|
+
const sourceMapping = options.sourceMapping !== false;
|
|
165
|
+
const inject = options.inject !== false;
|
|
166
|
+
const resolved = {
|
|
167
|
+
...options,
|
|
168
|
+
projectId: resolveProjectId(options.projectId, process.cwd())
|
|
169
|
+
};
|
|
170
|
+
return {
|
|
171
|
+
name: RETICLE_VITE_PLUGIN_NAME,
|
|
172
|
+
apply: "serve",
|
|
173
|
+
enforce: "pre",
|
|
174
|
+
transform(code, id) {
|
|
175
|
+
if (!sourceMapping || !shouldStamp(id))
|
|
176
|
+
return null;
|
|
177
|
+
return stamp(code, id);
|
|
178
|
+
},
|
|
179
|
+
resolveId(id) {
|
|
180
|
+
return inject && id === RETICLE_CONNECT_MODULE ? RETICLE_CONNECT_MODULE : null;
|
|
181
|
+
},
|
|
182
|
+
load(id) {
|
|
183
|
+
return inject && id === RETICLE_CONNECT_MODULE ? connectModuleSource(resolved) : null;
|
|
184
|
+
},
|
|
185
|
+
transformIndexHtml() {
|
|
186
|
+
if (!inject)
|
|
187
|
+
return [];
|
|
188
|
+
return [
|
|
189
|
+
{ tag: "script", attrs: { type: "module", src: RETICLE_CONNECT_MODULE }, injectTo: "body" }
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
export {
|
|
195
|
+
reticle
|
|
196
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reticlehq/core",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "One-install Reticle: the dev-only SDK (browser + React adapter) and the spec runner under one package, with subpaths for the source-mapping plugins and the MCP server.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
+
"repository": "github:reticlehq/reticle",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"reticle": "./dist/cli.js"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./server": {
|
|
20
|
+
"types": "./dist/server.d.ts",
|
|
21
|
+
"default": "./dist/server.js"
|
|
22
|
+
},
|
|
23
|
+
"./test": {
|
|
24
|
+
"types": "./dist/test.d.ts",
|
|
25
|
+
"default": "./dist/test.js"
|
|
26
|
+
},
|
|
27
|
+
"./next": {
|
|
28
|
+
"types": "./dist/next.d.ts",
|
|
29
|
+
"default": "./dist/next.js"
|
|
30
|
+
},
|
|
31
|
+
"./babel": {
|
|
32
|
+
"types": "./dist/babel.d.ts",
|
|
33
|
+
"default": "./dist/babel.js"
|
|
34
|
+
},
|
|
35
|
+
"./vite": {
|
|
36
|
+
"types": "./dist/vite.d.ts",
|
|
37
|
+
"default": "./dist/vite.js"
|
|
38
|
+
},
|
|
39
|
+
"./eslint": {
|
|
40
|
+
"types": "./dist/eslint.d.ts",
|
|
41
|
+
"default": "./dist/eslint.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@babel/core": "^7.26.0",
|
|
49
|
+
"@modelcontextprotocol/sdk": "^1.13.0",
|
|
50
|
+
"@testing-library/dom": "^10.4.1",
|
|
51
|
+
"@typescript-eslint/utils": "^8.20.0",
|
|
52
|
+
"ws": "^8.18.0",
|
|
53
|
+
"zod": "^3.24.1"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/ws": "^8.5.13",
|
|
57
|
+
"tsup": "^8.3.5",
|
|
58
|
+
"typescript": "^5.6.0",
|
|
59
|
+
"@reticlehq/babel-plugin": "1.3.0",
|
|
60
|
+
"@reticlehq/eslint-plugin": "1.3.0",
|
|
61
|
+
"@reticlehq/next": "1.3.0",
|
|
62
|
+
"@reticlehq/react": "1.3.0",
|
|
63
|
+
"@reticlehq/browser": "1.3.0",
|
|
64
|
+
"@reticlehq/protocol": "1.3.0",
|
|
65
|
+
"@reticlehq/test": "1.3.0",
|
|
66
|
+
"@reticlehq/server": "1.3.0",
|
|
67
|
+
"@reticlehq/vite-plugin": "1.3.0"
|
|
68
|
+
},
|
|
69
|
+
"optionalDependencies": {
|
|
70
|
+
"pixelmatch": "^7.2.0",
|
|
71
|
+
"playwright": "^1.48.0",
|
|
72
|
+
"pngjs": "^7.0.0"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"eslint": ">=9",
|
|
76
|
+
"next": ">=13",
|
|
77
|
+
"react": ">=18",
|
|
78
|
+
"vitest": "^3.2.6"
|
|
79
|
+
},
|
|
80
|
+
"peerDependenciesMeta": {
|
|
81
|
+
"eslint": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"next": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"react": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"vitest": {
|
|
91
|
+
"optional": true
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"scripts": {
|
|
95
|
+
"build": "tsup",
|
|
96
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
97
|
+
}
|
|
98
|
+
}
|