@elyracode/design-tools 0.9.56 → 0.9.57
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/extensions/index.ts +60 -91
- package/package.json +1 -1
package/extensions/index.ts
CHANGED
|
@@ -2,11 +2,35 @@ import { execSync } from "node:child_process";
|
|
|
2
2
|
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import type { ExtensionAPI } from "@elyracode/coding-agent";
|
|
5
|
+
import type { AgentToolResult, ExtensionAPI } from "@elyracode/coding-agent";
|
|
6
6
|
import { Type } from "typebox";
|
|
7
7
|
|
|
8
8
|
const PREVIEW_DIR = join(homedir(), ".elyra", "design-preview");
|
|
9
9
|
|
|
10
|
+
/** Details reported by design_preview. */
|
|
11
|
+
interface PreviewDetails {
|
|
12
|
+
path?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Details reported by screenshot_url. */
|
|
16
|
+
interface ScreenshotDetails {
|
|
17
|
+
path?: string;
|
|
18
|
+
width?: number;
|
|
19
|
+
height?: number;
|
|
20
|
+
selector?: string | null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Details reported by design_diff. */
|
|
24
|
+
interface DiffDetails {
|
|
25
|
+
before?: string;
|
|
26
|
+
after?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Details reported by design_system_check. */
|
|
30
|
+
interface SystemCheckDetails {
|
|
31
|
+
issueCount?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
10
34
|
export default function (elyra: ExtensionAPI): void {
|
|
11
35
|
// ── Tool 1: design_preview ──
|
|
12
36
|
// Render a component in the browser with live Tailwind CSS
|
|
@@ -20,8 +44,7 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
20
44
|
"The user can see the result visually while you iterate on the code.",
|
|
21
45
|
parameters: Type.Object({
|
|
22
46
|
html: Type.String({
|
|
23
|
-
description:
|
|
24
|
-
"The HTML content to preview (can include Tailwind classes, inline styles, etc.)",
|
|
47
|
+
description: "The HTML content to preview (can include Tailwind classes, inline styles, etc.)",
|
|
25
48
|
}),
|
|
26
49
|
title: Type.Optional(
|
|
27
50
|
Type.String({
|
|
@@ -35,12 +58,11 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
35
58
|
),
|
|
36
59
|
width: Type.Optional(
|
|
37
60
|
Type.String({
|
|
38
|
-
description:
|
|
39
|
-
"Container max-width (e.g., '800px', '100%'). Default: '1200px'",
|
|
61
|
+
description: "Container max-width (e.g., '800px', '100%'). Default: '1200px'",
|
|
40
62
|
}),
|
|
41
63
|
),
|
|
42
64
|
}),
|
|
43
|
-
execute: async (_toolCallId, params) => {
|
|
65
|
+
execute: async (_toolCallId, params): Promise<AgentToolResult<PreviewDetails>> => {
|
|
44
66
|
try {
|
|
45
67
|
if (!existsSync(PREVIEW_DIR)) {
|
|
46
68
|
mkdirSync(PREVIEW_DIR, { recursive: true });
|
|
@@ -49,9 +71,7 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
49
71
|
const title = params.title ?? "Elyra Design Preview";
|
|
50
72
|
const dark = params.dark ?? false;
|
|
51
73
|
const width = params.width ?? "1200px";
|
|
52
|
-
const bgClass = dark
|
|
53
|
-
? "bg-gray-900 text-white"
|
|
54
|
-
: "bg-white text-gray-900";
|
|
74
|
+
const bgClass = dark ? "bg-gray-900 text-white" : "bg-white text-gray-900";
|
|
55
75
|
|
|
56
76
|
const fullHtml = `<!DOCTYPE html>
|
|
57
77
|
<html lang="en" ${dark ? 'class="dark"' : ""}>
|
|
@@ -87,11 +107,7 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
87
107
|
|
|
88
108
|
// Open in default browser
|
|
89
109
|
const openCmd =
|
|
90
|
-
process.platform === "darwin"
|
|
91
|
-
? "open"
|
|
92
|
-
: process.platform === "win32"
|
|
93
|
-
? "start"
|
|
94
|
-
: "xdg-open";
|
|
110
|
+
process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
95
111
|
|
|
96
112
|
try {
|
|
97
113
|
execSync(`${openCmd} "${previewPath}"`, { timeout: 5000 });
|
|
@@ -109,8 +125,7 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
109
125
|
details: { path: previewPath },
|
|
110
126
|
};
|
|
111
127
|
} catch (error) {
|
|
112
|
-
const msg =
|
|
113
|
-
error instanceof Error ? error.message : String(error);
|
|
128
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
114
129
|
return {
|
|
115
130
|
content: [
|
|
116
131
|
{
|
|
@@ -138,8 +153,7 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
138
153
|
"Requires the 'screenshot' CLI tool (macOS built-in) or Puppeteer.",
|
|
139
154
|
parameters: Type.Object({
|
|
140
155
|
url: Type.String({
|
|
141
|
-
description:
|
|
142
|
-
"URL to screenshot (e.g., http://localhost:8000, or file path from design_preview)",
|
|
156
|
+
description: "URL to screenshot (e.g., http://localhost:8000, or file path from design_preview)",
|
|
143
157
|
}),
|
|
144
158
|
width: Type.Optional(
|
|
145
159
|
Type.Number({
|
|
@@ -153,8 +167,7 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
153
167
|
),
|
|
154
168
|
mobile: Type.Optional(
|
|
155
169
|
Type.Boolean({
|
|
156
|
-
description:
|
|
157
|
-
"Use mobile viewport (375x812) (default: false)",
|
|
170
|
+
description: "Use mobile viewport (375x812) (default: false)",
|
|
158
171
|
}),
|
|
159
172
|
),
|
|
160
173
|
selector: Type.Optional(
|
|
@@ -165,12 +178,11 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
165
178
|
),
|
|
166
179
|
full_page: Type.Optional(
|
|
167
180
|
Type.Boolean({
|
|
168
|
-
description:
|
|
169
|
-
"Capture the full scrollable page instead of just the viewport (default: false)",
|
|
181
|
+
description: "Capture the full scrollable page instead of just the viewport (default: false)",
|
|
170
182
|
}),
|
|
171
183
|
),
|
|
172
184
|
}),
|
|
173
|
-
execute: async (_toolCallId, params) => {
|
|
185
|
+
execute: async (_toolCallId, params): Promise<AgentToolResult<ScreenshotDetails>> => {
|
|
174
186
|
try {
|
|
175
187
|
if (!existsSync(PREVIEW_DIR)) {
|
|
176
188
|
mkdirSync(PREVIEW_DIR, { recursive: true });
|
|
@@ -284,8 +296,7 @@ await browser.close();
|
|
|
284
296
|
details: { path: screenshotPath, width, height, selector: params.selector ?? null },
|
|
285
297
|
};
|
|
286
298
|
} catch (error) {
|
|
287
|
-
const msg =
|
|
288
|
-
error instanceof Error ? error.message : String(error);
|
|
299
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
289
300
|
return {
|
|
290
301
|
content: [
|
|
291
302
|
{
|
|
@@ -321,7 +332,7 @@ await browser.close();
|
|
|
321
332
|
}),
|
|
322
333
|
),
|
|
323
334
|
}),
|
|
324
|
-
execute: async (_toolCallId, params) => {
|
|
335
|
+
execute: async (_toolCallId, params): Promise<AgentToolResult<DiffDetails>> => {
|
|
325
336
|
try {
|
|
326
337
|
let beforePath = params.before;
|
|
327
338
|
let afterPath = params.after;
|
|
@@ -389,18 +400,16 @@ await browser.close();
|
|
|
389
400
|
parameters: Type.Object({
|
|
390
401
|
file_path: Type.Optional(
|
|
391
402
|
Type.String({
|
|
392
|
-
description:
|
|
393
|
-
"Path to a file to analyze (Vue, Blade, TSX, HTML)",
|
|
403
|
+
description: "Path to a file to analyze (Vue, Blade, TSX, HTML)",
|
|
394
404
|
}),
|
|
395
405
|
),
|
|
396
406
|
html: Type.Optional(
|
|
397
407
|
Type.String({
|
|
398
|
-
description:
|
|
399
|
-
"HTML snippet to analyze (alternative to file_path)",
|
|
408
|
+
description: "HTML snippet to analyze (alternative to file_path)",
|
|
400
409
|
}),
|
|
401
410
|
),
|
|
402
411
|
}),
|
|
403
|
-
execute: async (_toolCallId, params) => {
|
|
412
|
+
execute: async (_toolCallId, params): Promise<AgentToolResult<SystemCheckDetails>> => {
|
|
404
413
|
try {
|
|
405
414
|
let content: string;
|
|
406
415
|
if (params.file_path) {
|
|
@@ -423,10 +432,7 @@ await browser.close();
|
|
|
423
432
|
|
|
424
433
|
// Check for mixed spacing scales
|
|
425
434
|
const spacingValues = new Set<string>();
|
|
426
|
-
const spacingMatches =
|
|
427
|
-
content.match(
|
|
428
|
-
/(?:p|m|gap|space)-(?:x-|y-)?(\d+)/g,
|
|
429
|
-
) ?? [];
|
|
435
|
+
const spacingMatches = content.match(/(?:p|m|gap|space)-(?:x-|y-)?(\d+)/g) ?? [];
|
|
430
436
|
for (const match of spacingMatches) {
|
|
431
437
|
const num = match.match(/(\d+)$/)?.[1];
|
|
432
438
|
if (num) spacingValues.add(num);
|
|
@@ -438,27 +444,17 @@ await browser.close();
|
|
|
438
444
|
}
|
|
439
445
|
|
|
440
446
|
// Check for missing responsive prefixes on layout classes
|
|
441
|
-
const gridCols =
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
content.match(
|
|
445
|
-
/(?:sm|md|lg|xl):grid-cols-\d+/g,
|
|
446
|
-
) ?? [];
|
|
447
|
-
if (
|
|
448
|
-
gridCols.length > 0 &&
|
|
449
|
-
responsiveGridCols.length === 0
|
|
450
|
-
) {
|
|
447
|
+
const gridCols = content.match(/grid-cols-\d+/g) ?? [];
|
|
448
|
+
const responsiveGridCols = content.match(/(?:sm|md|lg|xl):grid-cols-\d+/g) ?? [];
|
|
449
|
+
if (gridCols.length > 0 && responsiveGridCols.length === 0) {
|
|
451
450
|
issues.push(
|
|
452
451
|
"[Responsive] Grid columns used without responsive breakpoints. Add sm:/md:/lg: prefixes for mobile support.",
|
|
453
452
|
);
|
|
454
453
|
}
|
|
455
454
|
|
|
456
455
|
// Check for missing focus/hover states on interactive elements
|
|
457
|
-
const hasButtons = /button|btn|click|submit/i.test(
|
|
458
|
-
|
|
459
|
-
);
|
|
460
|
-
const hasFocusStates =
|
|
461
|
-
/focus:|focus-visible:/i.test(content);
|
|
456
|
+
const hasButtons = /button|btn|click|submit/i.test(content);
|
|
457
|
+
const hasFocusStates = /focus:|focus-visible:/i.test(content);
|
|
462
458
|
const hasHoverStates = /hover:/i.test(content);
|
|
463
459
|
if (hasButtons && !hasFocusStates) {
|
|
464
460
|
issues.push(
|
|
@@ -472,10 +468,7 @@ await browser.close();
|
|
|
472
468
|
}
|
|
473
469
|
|
|
474
470
|
// Check for hardcoded colors vs theme colors
|
|
475
|
-
const hardcodedColors =
|
|
476
|
-
content.match(
|
|
477
|
-
/(?:bg|text|border)-\[#[0-9a-fA-F]+\]/g,
|
|
478
|
-
) ?? [];
|
|
471
|
+
const hardcodedColors = content.match(/(?:bg|text|border)-\[#[0-9a-fA-F]+\]/g) ?? [];
|
|
479
472
|
if (hardcodedColors.length > 0) {
|
|
480
473
|
issues.push(
|
|
481
474
|
`[Colors] ${hardcodedColors.length} hardcoded color values found. Consider using Tailwind theme colors for consistency.`,
|
|
@@ -483,9 +476,7 @@ await browser.close();
|
|
|
483
476
|
}
|
|
484
477
|
|
|
485
478
|
// Check for conflicting classes
|
|
486
|
-
const hasHidden =
|
|
487
|
-
/\bhidden\b/.test(content) &&
|
|
488
|
-
/\bblock\b/.test(content);
|
|
479
|
+
const hasHidden = /\bhidden\b/.test(content) && /\bblock\b/.test(content);
|
|
489
480
|
if (hasHidden) {
|
|
490
481
|
issues.push(
|
|
491
482
|
"[Conflict] Both 'hidden' and 'block' classes found. These may conflict unless used with responsive prefixes.",
|
|
@@ -494,8 +485,7 @@ await browser.close();
|
|
|
494
485
|
|
|
495
486
|
// Check for missing dark mode support
|
|
496
487
|
const hasDarkClasses = /dark:/i.test(content);
|
|
497
|
-
const hasBgColor =
|
|
498
|
-
/bg-(?:white|gray|slate|zinc)/i.test(content);
|
|
488
|
+
const hasBgColor = /bg-(?:white|gray|slate|zinc)/i.test(content);
|
|
499
489
|
if (hasBgColor && !hasDarkClasses) {
|
|
500
490
|
issues.push(
|
|
501
491
|
"[Dark Mode] Background colors used without dark: variants. Add dark: prefixes for dark mode support.",
|
|
@@ -503,44 +493,29 @@ await browser.close();
|
|
|
503
493
|
}
|
|
504
494
|
|
|
505
495
|
// Check for text truncation without overflow handling
|
|
506
|
-
const hasTruncate =
|
|
507
|
-
|
|
508
|
-
const hasOverflow =
|
|
509
|
-
/overflow-hidden|overflow-auto/i.test(content);
|
|
496
|
+
const hasTruncate = /truncate|line-clamp/i.test(content);
|
|
497
|
+
const hasOverflow = /overflow-hidden|overflow-auto/i.test(content);
|
|
510
498
|
if (hasTruncate && !hasOverflow) {
|
|
511
|
-
issues.push(
|
|
512
|
-
"[Layout] Text truncation used without overflow handling on parent container.",
|
|
513
|
-
);
|
|
499
|
+
issues.push("[Layout] Text truncation used without overflow handling on parent container.");
|
|
514
500
|
}
|
|
515
501
|
|
|
516
|
-
const report: string[] = [
|
|
517
|
-
`# Design System Check${params.file_path ? `: ${params.file_path}` : ""}`,
|
|
518
|
-
"",
|
|
519
|
-
];
|
|
502
|
+
const report: string[] = [`# Design System Check${params.file_path ? `: ${params.file_path}` : ""}`, ""];
|
|
520
503
|
|
|
521
504
|
if (issues.length === 0) {
|
|
522
|
-
report.push(
|
|
523
|
-
"No design consistency issues found.",
|
|
524
|
-
);
|
|
505
|
+
report.push("No design consistency issues found.");
|
|
525
506
|
} else {
|
|
526
|
-
report.push(
|
|
527
|
-
`Found ${issues.length} issue${issues.length > 1 ? "s" : ""}:`,
|
|
528
|
-
"",
|
|
529
|
-
);
|
|
507
|
+
report.push(`Found ${issues.length} issue${issues.length > 1 ? "s" : ""}:`, "");
|
|
530
508
|
for (const issue of issues) {
|
|
531
509
|
report.push(`- ${issue}`);
|
|
532
510
|
}
|
|
533
511
|
}
|
|
534
512
|
|
|
535
513
|
return {
|
|
536
|
-
content: [
|
|
537
|
-
{ type: "text", text: report.join("\n") },
|
|
538
|
-
],
|
|
514
|
+
content: [{ type: "text", text: report.join("\n") }],
|
|
539
515
|
details: { issueCount: issues.length },
|
|
540
516
|
};
|
|
541
517
|
} catch (error) {
|
|
542
|
-
const msg =
|
|
543
|
-
error instanceof Error ? error.message : String(error);
|
|
518
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
544
519
|
return {
|
|
545
520
|
content: [
|
|
546
521
|
{
|
|
@@ -556,8 +531,7 @@ await browser.close();
|
|
|
556
531
|
|
|
557
532
|
// ── Command: /design ──
|
|
558
533
|
elyra.registerCommand("design", {
|
|
559
|
-
description:
|
|
560
|
-
"Design tools: live preview, screenshots, design system check",
|
|
534
|
+
description: "Design tools: live preview, screenshots, design system check",
|
|
561
535
|
handler: async (_args: string, ctx) => {
|
|
562
536
|
const options = [
|
|
563
537
|
"Preview -- render HTML/Tailwind in the browser",
|
|
@@ -566,10 +540,7 @@ await browser.close();
|
|
|
566
540
|
"Design Check -- analyze Tailwind classes for consistency",
|
|
567
541
|
];
|
|
568
542
|
|
|
569
|
-
const selected = await ctx.ui.select(
|
|
570
|
-
"Design Tools",
|
|
571
|
-
options,
|
|
572
|
-
);
|
|
543
|
+
const selected = await ctx.ui.select("Design Tools", options);
|
|
573
544
|
if (!selected) return;
|
|
574
545
|
|
|
575
546
|
if (selected.startsWith("Preview")) {
|
|
@@ -577,9 +548,7 @@ await browser.close();
|
|
|
577
548
|
"I want to preview a UI component. Describe what you want to see or give me the HTML/Tailwind code.",
|
|
578
549
|
);
|
|
579
550
|
} else if (selected.startsWith("Screenshot")) {
|
|
580
|
-
elyra.sendUserMessage(
|
|
581
|
-
"I want to take a screenshot of a page for visual QA. What URL should I capture?",
|
|
582
|
-
);
|
|
551
|
+
elyra.sendUserMessage("I want to take a screenshot of a page for visual QA. What URL should I capture?");
|
|
583
552
|
} else if (selected.startsWith("Diff")) {
|
|
584
553
|
elyra.sendUserMessage(
|
|
585
554
|
"I want to compare before/after screenshots of a UI change. Capture a before, make the change, capture an after, then diff them.",
|