design-brain-memory 0.2.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/README.md +167 -0
- package/dist/agentBrowser.d.ts +9 -0
- package/dist/agentBrowser.js +96 -0
- package/dist/agentBrowser.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +212 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands.d.ts +27 -0
- package/dist/commands.js +178 -0
- package/dist/commands.js.map +1 -0
- package/dist/extractFromImage.d.ts +7 -0
- package/dist/extractFromImage.js +72 -0
- package/dist/extractFromImage.js.map +1 -0
- package/dist/extractFromUrl.d.ts +13 -0
- package/dist/extractFromUrl.js +605 -0
- package/dist/extractFromUrl.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/interactive.d.ts +3 -0
- package/dist/interactive.js +42 -0
- package/dist/interactive.js.map +1 -0
- package/dist/llm.d.ts +33 -0
- package/dist/llm.js +250 -0
- package/dist/llm.js.map +1 -0
- package/dist/query.d.ts +25 -0
- package/dist/query.js +150 -0
- package/dist/query.js.map +1 -0
- package/dist/render.d.ts +2 -0
- package/dist/render.js +365 -0
- package/dist/render.js.map +1 -0
- package/dist/skillPrompt.d.ts +3 -0
- package/dist/skillPrompt.js +66 -0
- package/dist/skillPrompt.js.map +1 -0
- package/dist/store.d.ts +14 -0
- package/dist/store.js +69 -0
- package/dist/store.js.map +1 -0
- package/dist/svg.d.ts +5 -0
- package/dist/svg.js +162 -0
- package/dist/svg.js.map +1 -0
- package/dist/types.d.ts +175 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +9 -0
- package/dist/util.js +51 -0
- package/dist/util.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { runAgentBrowserJson } from './agentBrowser.js';
|
|
4
|
+
const DEFAULT_VIEWPORTS = [
|
|
5
|
+
{ label: 'desktop', width: 1440, height: 1200 },
|
|
6
|
+
{ label: 'tablet', width: 1024, height: 1366 },
|
|
7
|
+
{ label: 'mobile', width: 390, height: 844 },
|
|
8
|
+
];
|
|
9
|
+
const EXTRACTION_SCRIPT = String.raw `(() => {
|
|
10
|
+
const maxNodes = 2000;
|
|
11
|
+
const nodes = Array.from(document.querySelectorAll('body *')).slice(0, maxNodes);
|
|
12
|
+
|
|
13
|
+
const colorMap = new Map();
|
|
14
|
+
const typographyMap = new Map();
|
|
15
|
+
const componentList = [];
|
|
16
|
+
const motionList = [];
|
|
17
|
+
const layoutList = [];
|
|
18
|
+
const variableMap = {};
|
|
19
|
+
const stateStyleList = [];
|
|
20
|
+
|
|
21
|
+
const componentTags = new Set(['button', 'a', 'input', 'select', 'textarea', 'nav', 'header', 'footer', 'form']);
|
|
22
|
+
const maxComponents = 220;
|
|
23
|
+
const maxMotion = 220;
|
|
24
|
+
const maxStateStyles = 260;
|
|
25
|
+
|
|
26
|
+
function normalizeWhitespace(text) {
|
|
27
|
+
return (text || '').replace(/\s+/g, ' ').trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function pushColor(value, sample) {
|
|
31
|
+
if (!value || value === 'transparent' || value === 'rgba(0, 0, 0, 0)') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const parsed = parseCssColor(value);
|
|
36
|
+
if (!parsed) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const key = parsed.toUpperCase();
|
|
41
|
+
const entry = colorMap.get(key) || { hex: key, count: 0, samples: [] };
|
|
42
|
+
entry.count += 1;
|
|
43
|
+
if (sample && entry.samples.length < 5 && !entry.samples.includes(sample)) {
|
|
44
|
+
entry.samples.push(sample);
|
|
45
|
+
}
|
|
46
|
+
colorMap.set(key, entry);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function parseCssColor(input) {
|
|
50
|
+
if (!input) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const value = input.toString().trim().toLowerCase();
|
|
55
|
+
|
|
56
|
+
if (value.startsWith('#')) {
|
|
57
|
+
if (value.length === 4) {
|
|
58
|
+
return ('#' + value[1] + value[1] + value[2] + value[2] + value[3] + value[3]);
|
|
59
|
+
}
|
|
60
|
+
if (value.length === 7) {
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const rgbMatch = value.match(/rgba?\(([^)]+)\)/);
|
|
67
|
+
if (rgbMatch) {
|
|
68
|
+
const parts = rgbMatch[1].split(',').map((part) => part.trim());
|
|
69
|
+
const r = Number(parts[0]);
|
|
70
|
+
const g = Number(parts[1]);
|
|
71
|
+
const b = Number(parts[2]);
|
|
72
|
+
if ([r, g, b].some((n) => Number.isNaN(n))) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const toHex = (n) => Math.max(0, Math.min(255, n)).toString(16).padStart(2, '0');
|
|
76
|
+
return '#' + toHex(r) + toHex(g) + toHex(b);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function buildSelector(el) {
|
|
83
|
+
const tag = el.tagName.toLowerCase();
|
|
84
|
+
if (el.id) {
|
|
85
|
+
return tag + '#' + el.id;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (typeof el.className === 'string' && el.className.trim()) {
|
|
89
|
+
const firstClass = el.className.trim().split(/\s+/).slice(0, 2).join('.');
|
|
90
|
+
if (firstClass) {
|
|
91
|
+
return tag + '.' + firstClass;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return tag;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function addTypography(style) {
|
|
99
|
+
const key = [style.fontFamily, style.fontSize, style.fontWeight, style.lineHeight].join('|');
|
|
100
|
+
const existing = typographyMap.get(key) || {
|
|
101
|
+
fontFamily: style.fontFamily,
|
|
102
|
+
fontSize: style.fontSize,
|
|
103
|
+
fontWeight: style.fontWeight,
|
|
104
|
+
lineHeight: style.lineHeight,
|
|
105
|
+
count: 0,
|
|
106
|
+
};
|
|
107
|
+
existing.count += 1;
|
|
108
|
+
typographyMap.set(key, existing);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function shouldCaptureAsComponent(el, selector) {
|
|
112
|
+
const tag = el.tagName.toLowerCase();
|
|
113
|
+
if (componentTags.has(tag)) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const className = typeof el.className === 'string' ? el.className.toLowerCase() : '';
|
|
118
|
+
if (className.includes('btn') || className.includes('button') || className.includes('card') || className.includes('hero')) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (el.getAttribute('role') === 'button' || el.getAttribute('role') === 'navigation') {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return selector.startsWith('section.') || selector.startsWith('div.card');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function addPseudoStateStyles() {
|
|
130
|
+
const stateKinds = [':hover', ':focus', ':active'];
|
|
131
|
+
|
|
132
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
133
|
+
let rules;
|
|
134
|
+
try {
|
|
135
|
+
rules = sheet.cssRules;
|
|
136
|
+
} catch {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!rules) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
for (const rule of Array.from(rules)) {
|
|
145
|
+
const selectorText = 'selectorText' in rule ? String(rule.selectorText || '') : '';
|
|
146
|
+
const style = 'style' in rule ? rule.style : undefined;
|
|
147
|
+
if (!selectorText || !style) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
for (const stateKind of stateKinds) {
|
|
152
|
+
if (!selectorText.includes(stateKind)) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const declarations = {};
|
|
157
|
+
for (const prop of ['color', 'background-color', 'border-color', 'box-shadow', 'transform', 'transition', 'opacity']) {
|
|
158
|
+
const value = style.getPropertyValue(prop);
|
|
159
|
+
if (value) {
|
|
160
|
+
declarations[prop] = value;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (Object.keys(declarations).length === 0) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const cleanSelector = selectorText.split(stateKind).join('').trim();
|
|
169
|
+
stateStyleList.push({
|
|
170
|
+
selector: cleanSelector || selectorText,
|
|
171
|
+
state: stateKind.slice(1),
|
|
172
|
+
declarations,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
if (stateStyleList.length >= maxStateStyles) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
nodes.forEach((el) => {
|
|
184
|
+
const style = window.getComputedStyle(el);
|
|
185
|
+
|
|
186
|
+
if (style.display === 'none' || style.visibility === 'hidden' || Number(style.opacity) === 0) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const selector = buildSelector(el);
|
|
191
|
+
pushColor(style.color, selector + ':color');
|
|
192
|
+
pushColor(style.backgroundColor, selector + ':background');
|
|
193
|
+
|
|
194
|
+
if (style.borderColor && style.borderColor !== 'rgba(0, 0, 0, 0)') {
|
|
195
|
+
pushColor(style.borderColor, selector + ':border');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const hasText = normalizeWhitespace(el.textContent || '').length > 0;
|
|
199
|
+
if (hasText) {
|
|
200
|
+
addTypography(style);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (shouldCaptureAsComponent(el, selector) && componentList.length < maxComponents) {
|
|
204
|
+
componentList.push({
|
|
205
|
+
kind: inferComponentKind(el),
|
|
206
|
+
tag: el.tagName.toLowerCase(),
|
|
207
|
+
selector,
|
|
208
|
+
text: normalizeWhitespace(el.textContent || '').slice(0, 90),
|
|
209
|
+
className: typeof el.className === 'string' ? normalizeWhitespace(el.className) : '',
|
|
210
|
+
styles: {
|
|
211
|
+
color: style.color,
|
|
212
|
+
backgroundColor: style.backgroundColor,
|
|
213
|
+
borderRadius: style.borderRadius,
|
|
214
|
+
border: style.border,
|
|
215
|
+
padding: style.padding,
|
|
216
|
+
margin: style.margin,
|
|
217
|
+
fontSize: style.fontSize,
|
|
218
|
+
fontWeight: style.fontWeight,
|
|
219
|
+
boxShadow: style.boxShadow,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const hasTransition = style.transitionDuration && style.transitionDuration !== '0s';
|
|
225
|
+
const hasAnimation = style.animationName && style.animationName !== 'none';
|
|
226
|
+
const hasTransform = style.transform && style.transform !== 'none';
|
|
227
|
+
|
|
228
|
+
if ((hasTransition || hasAnimation || hasTransform) && motionList.length < maxMotion) {
|
|
229
|
+
motionList.push({
|
|
230
|
+
selector,
|
|
231
|
+
transition: style.transition,
|
|
232
|
+
animation: style.animation,
|
|
233
|
+
transform: style.transform,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const layoutSelectors = Array.from(document.querySelectorAll('header, nav, main, section, article, aside, footer')).slice(0, 160);
|
|
239
|
+
|
|
240
|
+
layoutSelectors.forEach((el) => {
|
|
241
|
+
layoutList.push({
|
|
242
|
+
tag: el.tagName.toLowerCase(),
|
|
243
|
+
selector: buildSelector(el),
|
|
244
|
+
role: el.getAttribute('role') || '',
|
|
245
|
+
children: el.children.length,
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
[document.documentElement, document.body].forEach((root) => {
|
|
250
|
+
if (!root) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const style = window.getComputedStyle(root);
|
|
255
|
+
for (const propertyName of style) {
|
|
256
|
+
if (!propertyName.startsWith('--')) {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
const value = style.getPropertyValue(propertyName).trim();
|
|
260
|
+
if (value) {
|
|
261
|
+
variableMap[propertyName] = value;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
function inferComponentKind(el) {
|
|
267
|
+
const tag = el.tagName.toLowerCase();
|
|
268
|
+
const className = typeof el.className === 'string' ? el.className.toLowerCase() : '';
|
|
269
|
+
if (tag === 'button' || className.includes('btn')) {
|
|
270
|
+
return 'button';
|
|
271
|
+
}
|
|
272
|
+
if (tag === 'a') {
|
|
273
|
+
return 'link';
|
|
274
|
+
}
|
|
275
|
+
if (tag === 'input' || tag === 'textarea' || tag === 'select') {
|
|
276
|
+
return 'form-control';
|
|
277
|
+
}
|
|
278
|
+
if (tag === 'nav' || className.includes('nav')) {
|
|
279
|
+
return 'navigation';
|
|
280
|
+
}
|
|
281
|
+
if (className.includes('card')) {
|
|
282
|
+
return 'card';
|
|
283
|
+
}
|
|
284
|
+
if (tag === 'header') {
|
|
285
|
+
return 'header';
|
|
286
|
+
}
|
|
287
|
+
if (tag === 'footer') {
|
|
288
|
+
return 'footer';
|
|
289
|
+
}
|
|
290
|
+
if (className.includes('hero')) {
|
|
291
|
+
return 'hero';
|
|
292
|
+
}
|
|
293
|
+
return tag;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
addPseudoStateStyles();
|
|
297
|
+
|
|
298
|
+
const colors = Array.from(colorMap.values()).sort((a, b) => b.count - a.count).slice(0, 70);
|
|
299
|
+
const typography = Array.from(typographyMap.values()).sort((a, b) => b.count - a.count).slice(0, 90);
|
|
300
|
+
|
|
301
|
+
return {
|
|
302
|
+
pageTitle: document.title,
|
|
303
|
+
pageUrl: window.location.href,
|
|
304
|
+
viewport: {
|
|
305
|
+
width: window.innerWidth,
|
|
306
|
+
height: window.innerHeight,
|
|
307
|
+
},
|
|
308
|
+
colors,
|
|
309
|
+
typography,
|
|
310
|
+
components: componentList,
|
|
311
|
+
motion: motionList,
|
|
312
|
+
layout: layoutList,
|
|
313
|
+
cssVariables: variableMap,
|
|
314
|
+
stateStyles: stateStyleList,
|
|
315
|
+
};
|
|
316
|
+
})();`;
|
|
317
|
+
const PAGE_SUMMARY_SCRIPT = String.raw `(() => {
|
|
318
|
+
const h1 = document.querySelector('h1')?.textContent?.trim() || '';
|
|
319
|
+
const navCount = document.querySelectorAll('nav a, header a').length;
|
|
320
|
+
const ctaCount = document.querySelectorAll('button, a[role="button"], .btn, .button').length;
|
|
321
|
+
return {
|
|
322
|
+
title: document.title,
|
|
323
|
+
url: window.location.href,
|
|
324
|
+
summary: [h1, 'nav-links:' + navCount, 'ctas:' + ctaCount].filter(Boolean).join(' | '),
|
|
325
|
+
};
|
|
326
|
+
})();`;
|
|
327
|
+
function normalizeResult(result) {
|
|
328
|
+
return {
|
|
329
|
+
pageTitle: result.pageTitle ?? undefined,
|
|
330
|
+
pageUrl: result.pageUrl ?? undefined,
|
|
331
|
+
viewport: result.viewport ?? undefined,
|
|
332
|
+
colors: result.colors ?? [],
|
|
333
|
+
typography: result.typography ?? [],
|
|
334
|
+
components: result.components ?? [],
|
|
335
|
+
motion: result.motion ?? [],
|
|
336
|
+
layout: result.layout ?? [],
|
|
337
|
+
cssVariables: result.cssVariables ?? {},
|
|
338
|
+
stateStyles: result.stateStyles ?? [],
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function mergeAnalysis(all) {
|
|
342
|
+
const first = all[0] ?? {
|
|
343
|
+
colors: [],
|
|
344
|
+
typography: [],
|
|
345
|
+
components: [],
|
|
346
|
+
motion: [],
|
|
347
|
+
layout: [],
|
|
348
|
+
cssVariables: {},
|
|
349
|
+
};
|
|
350
|
+
const colorMap = new Map();
|
|
351
|
+
for (const entry of all) {
|
|
352
|
+
for (const color of entry.colors) {
|
|
353
|
+
const existing = colorMap.get(color.hex) ?? { hex: color.hex, count: 0, samples: [] };
|
|
354
|
+
existing.count += color.count;
|
|
355
|
+
for (const sample of color.samples) {
|
|
356
|
+
if (existing.samples.length < 8 && !existing.samples.includes(sample)) {
|
|
357
|
+
existing.samples.push(sample);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
colorMap.set(color.hex, existing);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
const typographyMap = new Map();
|
|
364
|
+
for (const entry of all) {
|
|
365
|
+
for (const token of entry.typography) {
|
|
366
|
+
const key = `${token.fontFamily}|${token.fontSize}|${token.fontWeight}|${token.lineHeight}`;
|
|
367
|
+
const existing = typographyMap.get(key) ?? { ...token, count: 0 };
|
|
368
|
+
existing.count += token.count;
|
|
369
|
+
typographyMap.set(key, existing);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const componentMap = new Map();
|
|
373
|
+
const motionMap = new Map();
|
|
374
|
+
const layoutMap = new Map();
|
|
375
|
+
const stateMap = new Map();
|
|
376
|
+
const cssVariables = {};
|
|
377
|
+
for (const entry of all) {
|
|
378
|
+
Object.assign(cssVariables, entry.cssVariables);
|
|
379
|
+
for (const component of entry.components) {
|
|
380
|
+
const key = `${component.kind}|${component.selector}|${component.text}`;
|
|
381
|
+
if (!componentMap.has(key)) {
|
|
382
|
+
componentMap.set(key, component);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
for (const motion of entry.motion) {
|
|
386
|
+
const key = `${motion.selector}|${motion.transition}|${motion.animation}|${motion.transform}`;
|
|
387
|
+
if (!motionMap.has(key)) {
|
|
388
|
+
motionMap.set(key, motion);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
for (const layout of entry.layout) {
|
|
392
|
+
const key = `${layout.tag}|${layout.selector}|${layout.role}`;
|
|
393
|
+
if (!layoutMap.has(key)) {
|
|
394
|
+
layoutMap.set(key, layout);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
for (const state of entry.stateStyles ?? []) {
|
|
398
|
+
const key = `${state.selector}|${state.state}|${JSON.stringify(state.declarations)}`;
|
|
399
|
+
if (!stateMap.has(key)) {
|
|
400
|
+
stateMap.set(key, state);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return {
|
|
405
|
+
pageTitle: first.pageTitle,
|
|
406
|
+
pageUrl: first.pageUrl,
|
|
407
|
+
viewport: first.viewport,
|
|
408
|
+
colors: [...colorMap.values()].sort((a, b) => b.count - a.count).slice(0, 90),
|
|
409
|
+
typography: [...typographyMap.values()].sort((a, b) => b.count - a.count).slice(0, 120),
|
|
410
|
+
components: [...componentMap.values()].slice(0, 260),
|
|
411
|
+
motion: [...motionMap.values()].slice(0, 260),
|
|
412
|
+
layout: [...layoutMap.values()].slice(0, 220),
|
|
413
|
+
cssVariables,
|
|
414
|
+
stateStyles: [...stateMap.values()].slice(0, 300),
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function parseStylesFromGetStyles(data) {
|
|
418
|
+
const payload = data;
|
|
419
|
+
const first = payload.elements?.[0];
|
|
420
|
+
const styles = first?.styles ?? {};
|
|
421
|
+
const out = {};
|
|
422
|
+
for (const [key, value] of Object.entries(styles)) {
|
|
423
|
+
if (typeof value === 'string' && value.trim()) {
|
|
424
|
+
out[key] = value;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return out;
|
|
428
|
+
}
|
|
429
|
+
async function collectInteractiveStateStyles(params) {
|
|
430
|
+
const states = [];
|
|
431
|
+
const snapshot = await runAgentBrowserJson(['snapshot', '-i', '-d', '2'], {
|
|
432
|
+
session: params.sessionName,
|
|
433
|
+
cwd: params.workingDir,
|
|
434
|
+
});
|
|
435
|
+
const refs = (snapshot.data.refs ?? {});
|
|
436
|
+
const refIds = Object.keys(refs).slice(0, 8);
|
|
437
|
+
for (const refId of refIds) {
|
|
438
|
+
const ref = `@${refId}`;
|
|
439
|
+
await runAgentBrowserJson(['hover', ref], {
|
|
440
|
+
session: params.sessionName,
|
|
441
|
+
cwd: params.workingDir,
|
|
442
|
+
}).catch(() => undefined);
|
|
443
|
+
const hoverStyles = await runAgentBrowserJson(['get', 'styles', ref], {
|
|
444
|
+
session: params.sessionName,
|
|
445
|
+
cwd: params.workingDir,
|
|
446
|
+
}).catch(() => undefined);
|
|
447
|
+
if (hoverStyles?.success) {
|
|
448
|
+
const declarations = parseStylesFromGetStyles(hoverStyles.data);
|
|
449
|
+
if (Object.keys(declarations).length > 0) {
|
|
450
|
+
states.push({ selector: ref, state: 'hover', declarations });
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
await runAgentBrowserJson(['focus', ref], {
|
|
454
|
+
session: params.sessionName,
|
|
455
|
+
cwd: params.workingDir,
|
|
456
|
+
}).catch(() => undefined);
|
|
457
|
+
const focusStyles = await runAgentBrowserJson(['get', 'styles', ref], {
|
|
458
|
+
session: params.sessionName,
|
|
459
|
+
cwd: params.workingDir,
|
|
460
|
+
}).catch(() => undefined);
|
|
461
|
+
if (focusStyles?.success) {
|
|
462
|
+
const declarations = parseStylesFromGetStyles(focusStyles.data);
|
|
463
|
+
if (Object.keys(declarations).length > 0) {
|
|
464
|
+
states.push({ selector: ref, state: 'focus', declarations });
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return states;
|
|
469
|
+
}
|
|
470
|
+
function toResponsiveSnapshot(label, analysis) {
|
|
471
|
+
return {
|
|
472
|
+
label,
|
|
473
|
+
viewport: analysis.viewport ?? { width: 0, height: 0 },
|
|
474
|
+
url: analysis.pageUrl,
|
|
475
|
+
title: analysis.pageTitle,
|
|
476
|
+
colorCount: analysis.colors.length,
|
|
477
|
+
componentCount: analysis.components.length,
|
|
478
|
+
typographyCount: analysis.typography.length,
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
async function getCurrentUrl(params) {
|
|
482
|
+
const response = await runAgentBrowserJson(['get', 'url'], {
|
|
483
|
+
session: params.sessionName,
|
|
484
|
+
cwd: params.workingDir,
|
|
485
|
+
}).catch(() => undefined);
|
|
486
|
+
return response?.success ? response.data.url : undefined;
|
|
487
|
+
}
|
|
488
|
+
async function collectJourney(params) {
|
|
489
|
+
const steps = [];
|
|
490
|
+
if (params.maxSteps <= 0) {
|
|
491
|
+
return steps;
|
|
492
|
+
}
|
|
493
|
+
const snapshot = await runAgentBrowserJson(['snapshot', '-i', '-d', '2'], {
|
|
494
|
+
session: params.sessionName,
|
|
495
|
+
cwd: params.workingDir,
|
|
496
|
+
});
|
|
497
|
+
const refs = (snapshot.data.refs ?? {});
|
|
498
|
+
const clickable = Object.entries(refs)
|
|
499
|
+
.filter(([, value]) => ['link', 'button', 'menuitem', 'tab'].includes(String(value?.role ?? '')))
|
|
500
|
+
.slice(0, params.maxSteps);
|
|
501
|
+
for (let i = 0; i < clickable.length; i += 1) {
|
|
502
|
+
const [refId] = clickable[i];
|
|
503
|
+
const ref = `@${refId}`;
|
|
504
|
+
const fromUrl = await getCurrentUrl(params);
|
|
505
|
+
const clickResult = await runAgentBrowserJson(['click', ref], {
|
|
506
|
+
session: params.sessionName,
|
|
507
|
+
cwd: params.workingDir,
|
|
508
|
+
}).catch(() => undefined);
|
|
509
|
+
if (!clickResult?.success) {
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
await runAgentBrowserJson(['wait', '1200'], {
|
|
513
|
+
session: params.sessionName,
|
|
514
|
+
cwd: params.workingDir,
|
|
515
|
+
}).catch(() => undefined);
|
|
516
|
+
const summaryResult = await runAgentBrowserJson(['eval', PAGE_SUMMARY_SCRIPT], {
|
|
517
|
+
session: params.sessionName,
|
|
518
|
+
cwd: params.workingDir,
|
|
519
|
+
}).catch(() => undefined);
|
|
520
|
+
const summaryData = summaryResult?.data.result ?? {};
|
|
521
|
+
const toUrl = summaryData.url ?? (await getCurrentUrl(params));
|
|
522
|
+
if (toUrl && fromUrl && toUrl !== fromUrl) {
|
|
523
|
+
steps.push({
|
|
524
|
+
step: i + 1,
|
|
525
|
+
action: `click ${ref}`,
|
|
526
|
+
fromUrl,
|
|
527
|
+
toUrl,
|
|
528
|
+
title: summaryData.title,
|
|
529
|
+
summary: summaryData.summary,
|
|
530
|
+
});
|
|
531
|
+
await runAgentBrowserJson(['back'], {
|
|
532
|
+
session: params.sessionName,
|
|
533
|
+
cwd: params.workingDir,
|
|
534
|
+
}).catch(() => undefined);
|
|
535
|
+
await runAgentBrowserJson(['wait', '900'], {
|
|
536
|
+
session: params.sessionName,
|
|
537
|
+
cwd: params.workingDir,
|
|
538
|
+
}).catch(() => undefined);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return steps;
|
|
542
|
+
}
|
|
543
|
+
export async function captureDesignFromUrl(params) {
|
|
544
|
+
const { url, sessionName, screenshotPath, workingDir, journeySteps = 3, responsiveViewports = DEFAULT_VIEWPORTS, } = params;
|
|
545
|
+
await fs.ensureDir(path.dirname(screenshotPath));
|
|
546
|
+
await runAgentBrowserJson(['open', url], { session: sessionName, cwd: workingDir });
|
|
547
|
+
try {
|
|
548
|
+
const captures = [];
|
|
549
|
+
const responsiveSnapshots = [];
|
|
550
|
+
for (const viewport of responsiveViewports) {
|
|
551
|
+
await runAgentBrowserJson(['set', 'viewport', String(viewport.width), String(viewport.height)], {
|
|
552
|
+
session: sessionName,
|
|
553
|
+
cwd: workingDir,
|
|
554
|
+
});
|
|
555
|
+
await runAgentBrowserJson(['wait', '900'], {
|
|
556
|
+
session: sessionName,
|
|
557
|
+
cwd: workingDir,
|
|
558
|
+
});
|
|
559
|
+
const extraction = await runAgentBrowserJson(['eval', EXTRACTION_SCRIPT], {
|
|
560
|
+
session: sessionName,
|
|
561
|
+
cwd: workingDir,
|
|
562
|
+
});
|
|
563
|
+
if (!extraction.success) {
|
|
564
|
+
throw new Error(`Extraction failed: ${extraction.error ?? 'Unknown error'}`);
|
|
565
|
+
}
|
|
566
|
+
const normalized = normalizeResult(extraction.data.result ?? {});
|
|
567
|
+
captures.push(normalized);
|
|
568
|
+
responsiveSnapshots.push(toResponsiveSnapshot(viewport.label, normalized));
|
|
569
|
+
}
|
|
570
|
+
await runAgentBrowserJson(['set', 'viewport', '1440', '1200'], {
|
|
571
|
+
session: sessionName,
|
|
572
|
+
cwd: workingDir,
|
|
573
|
+
}).catch(() => undefined);
|
|
574
|
+
const snapshotResult = await runAgentBrowserJson(['snapshot', '-c', '-d', '3'], {
|
|
575
|
+
session: sessionName,
|
|
576
|
+
cwd: workingDir,
|
|
577
|
+
});
|
|
578
|
+
const interactiveStates = await collectInteractiveStateStyles({
|
|
579
|
+
sessionName,
|
|
580
|
+
workingDir,
|
|
581
|
+
});
|
|
582
|
+
const journey = await collectJourney({
|
|
583
|
+
sessionName,
|
|
584
|
+
workingDir,
|
|
585
|
+
maxSteps: journeySteps,
|
|
586
|
+
});
|
|
587
|
+
await runAgentBrowserJson(['screenshot', screenshotPath, '--full'], {
|
|
588
|
+
session: sessionName,
|
|
589
|
+
cwd: workingDir,
|
|
590
|
+
});
|
|
591
|
+
const merged = mergeAnalysis(captures);
|
|
592
|
+
const stateStyles = [...(merged.stateStyles ?? []), ...interactiveStates].slice(0, 400);
|
|
593
|
+
return {
|
|
594
|
+
...merged,
|
|
595
|
+
accessibilitySnapshot: snapshotResult.data.snapshot ?? undefined,
|
|
596
|
+
responsiveSnapshots,
|
|
597
|
+
stateStyles,
|
|
598
|
+
journey,
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
finally {
|
|
602
|
+
await runAgentBrowserJson(['close'], { session: sessionName, cwd: workingDir }).catch(() => undefined);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
//# sourceMappingURL=extractFromUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractFromUrl.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estInspiration, recordOutcome, reindexBrain, searchBrain, } from './commands.js';
|
|
2
|
+
export { askDesignBrain, searchDesignBrain } from './query.js';
|
|
3
|
+
export type { ColorToken, ComponentToken, DesignAnalysis, DesignBrainDatabase, InspirationDiff, InspirationRecord, LayoutToken, LlmConfig, LlmEnrichment, MotionToken, OutcomeRecord, ProjectRecord, ResponsiveSnapshot, StateStyleToken, TypographyToken, } from './types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import readline from 'node:readline/promises';
|
|
2
|
+
import { stdin as input, stdout as output } from 'node:process';
|
|
3
|
+
const AUTOMATED_ENV_VARS = [
|
|
4
|
+
'CI',
|
|
5
|
+
'CLAUDECODE',
|
|
6
|
+
'CURSOR_AGENT',
|
|
7
|
+
'CODEX_CI',
|
|
8
|
+
'OPENCODE',
|
|
9
|
+
'AMP_HOME',
|
|
10
|
+
'AMI',
|
|
11
|
+
];
|
|
12
|
+
export function isAutomatedEnvironment() {
|
|
13
|
+
return AUTOMATED_ENV_VARS.some((name) => Boolean(process.env[name]));
|
|
14
|
+
}
|
|
15
|
+
export function shouldSkipPrompts(yesFlag) {
|
|
16
|
+
return yesFlag || isAutomatedEnvironment() || !process.stdin.isTTY;
|
|
17
|
+
}
|
|
18
|
+
export async function confirmPrompt(message, defaultYes = true) {
|
|
19
|
+
if (!process.stdin.isTTY) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const suffix = defaultYes ? ' [Y/n] ' : ' [y/N] ';
|
|
23
|
+
const rl = readline.createInterface({ input, output });
|
|
24
|
+
try {
|
|
25
|
+
const raw = await rl.question(`${message}${suffix}`);
|
|
26
|
+
const answer = raw.trim().toLowerCase();
|
|
27
|
+
if (!answer) {
|
|
28
|
+
return defaultYes;
|
|
29
|
+
}
|
|
30
|
+
if (answer === 'y' || answer === 'yes') {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (answer === 'n' || answer === 'no') {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return defaultYes;
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
rl.close();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=interactive.js.map
|