@defai.digital/ax-cli 3.14.9 → 3.14.11
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 +17 -2
- package/dist/agent/execution/tool-executor.d.ts +6 -0
- package/dist/agent/execution/tool-executor.js +72 -0
- package/dist/agent/execution/tool-executor.js.map +1 -1
- package/dist/commands/design.d.ts +18 -0
- package/dist/commands/design.js +495 -0
- package/dist/commands/design.js.map +1 -0
- package/dist/commands/vscode.js +1 -1
- package/dist/commands/vscode.js.map +1 -1
- package/dist/design/figma-alias.d.ts +88 -0
- package/dist/design/figma-alias.js +324 -0
- package/dist/design/figma-alias.js.map +1 -0
- package/dist/design/figma-audit.d.ts +40 -0
- package/dist/design/figma-audit.js +375 -0
- package/dist/design/figma-audit.js.map +1 -0
- package/dist/design/figma-client.d.ts +123 -0
- package/dist/design/figma-client.js +316 -0
- package/dist/design/figma-client.js.map +1 -0
- package/dist/design/figma-map.d.ts +29 -0
- package/dist/design/figma-map.js +274 -0
- package/dist/design/figma-map.js.map +1 -0
- package/dist/design/figma-tokens.d.ts +73 -0
- package/dist/design/figma-tokens.js +431 -0
- package/dist/design/figma-tokens.js.map +1 -0
- package/dist/design/index.d.ts +13 -0
- package/dist/design/index.js +18 -0
- package/dist/design/index.js.map +1 -0
- package/dist/design/types.d.ts +89 -0
- package/dist/design/types.js +9 -0
- package/dist/design/types.js.map +1 -0
- package/dist/hooks/hook-runner.js +2 -2
- package/dist/hooks/hook-runner.js.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/ipc/vscode-client.js +1 -1
- package/dist/ipc/vscode-client.js.map +1 -1
- package/dist/llm/tools.js +170 -0
- package/dist/llm/tools.js.map +1 -1
- package/dist/mcp/client-v2.js +1 -1
- package/dist/mcp/client-v2.js.map +1 -1
- package/dist/mcp/validation.js +1 -1
- package/dist/mcp/validation.js.map +1 -1
- package/dist/permissions/permission-manager.js +2 -2
- package/dist/permissions/permission-manager.js.map +1 -1
- package/dist/tools/design-tool.d.ts +59 -0
- package/dist/tools/design-tool.js +258 -0
- package/dist/tools/design-tool.js.map +1 -0
- package/dist/ui/hooks/use-input-history.js +1 -1
- package/dist/ui/hooks/use-input-history.js.map +1 -1
- package/dist/ui/utils/image-handler.js +1 -1
- package/dist/ui/utils/image-handler.js.map +1 -1
- package/dist/utils/path-security.js +2 -2
- package/dist/utils/path-security.js.map +1 -1
- package/dist/utils/progress-tracker.js +1 -1
- package/dist/utils/progress-tracker.js.map +1 -1
- package/dist/utils/settings-manager.js +8 -3
- package/dist/utils/settings-manager.js.map +1 -1
- package/node_modules/@ax-cli/schemas/dist/index.d.ts +1 -0
- package/node_modules/@ax-cli/schemas/dist/index.d.ts.map +1 -1
- package/node_modules/@ax-cli/schemas/dist/index.js +2 -2
- package/node_modules/@ax-cli/schemas/dist/index.js.map +1 -1
- package/node_modules/@ax-cli/schemas/dist/public/design/alias-types.d.ts +346 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/alias-types.d.ts.map +1 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/alias-types.js +171 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/alias-types.js.map +1 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/audit-types.d.ts +545 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/audit-types.d.ts.map +1 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/audit-types.js +307 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/audit-types.js.map +1 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/figma-types.d.ts +1306 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/figma-types.d.ts.map +1 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/figma-types.js +428 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/figma-types.js.map +1 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/index.d.ts +13 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/index.d.ts.map +1 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/index.js +82 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/index.js.map +1 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/token-types.d.ts +1245 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/token-types.d.ts.map +1 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/token-types.js +282 -0
- package/node_modules/@ax-cli/schemas/dist/public/design/token-types.js.map +1 -0
- package/package.json +2 -2
- package/packages/schemas/dist/index.d.ts +1 -0
- package/packages/schemas/dist/index.d.ts.map +1 -1
- package/packages/schemas/dist/index.js +2 -2
- package/packages/schemas/dist/index.js.map +1 -1
- package/packages/schemas/dist/public/design/alias-types.d.ts +346 -0
- package/packages/schemas/dist/public/design/alias-types.d.ts.map +1 -0
- package/packages/schemas/dist/public/design/alias-types.js +171 -0
- package/packages/schemas/dist/public/design/alias-types.js.map +1 -0
- package/packages/schemas/dist/public/design/audit-types.d.ts +545 -0
- package/packages/schemas/dist/public/design/audit-types.d.ts.map +1 -0
- package/packages/schemas/dist/public/design/audit-types.js +307 -0
- package/packages/schemas/dist/public/design/audit-types.js.map +1 -0
- package/packages/schemas/dist/public/design/figma-types.d.ts +1306 -0
- package/packages/schemas/dist/public/design/figma-types.d.ts.map +1 -0
- package/packages/schemas/dist/public/design/figma-types.js +428 -0
- package/packages/schemas/dist/public/design/figma-types.js.map +1 -0
- package/packages/schemas/dist/public/design/index.d.ts +13 -0
- package/packages/schemas/dist/public/design/index.d.ts.map +1 -0
- package/packages/schemas/dist/public/design/index.js +82 -0
- package/packages/schemas/dist/public/design/index.js.map +1 -0
- package/packages/schemas/dist/public/design/token-types.d.ts +1245 -0
- package/packages/schemas/dist/public/design/token-types.d.ts.map +1 -0
- package/packages/schemas/dist/public/design/token-types.js +282 -0
- package/packages/schemas/dist/public/design/token-types.js.map +1 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Figma Design Audit
|
|
3
|
+
*
|
|
4
|
+
* Rule-based audit system for checking design consistency,
|
|
5
|
+
* accessibility, and best practices.
|
|
6
|
+
*
|
|
7
|
+
* @module design/figma-audit
|
|
8
|
+
*/
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// Generic Layer Naming Patterns
|
|
11
|
+
// =============================================================================
|
|
12
|
+
const GENERIC_NAMES = [
|
|
13
|
+
/^Frame \d+$/i,
|
|
14
|
+
/^Rectangle \d+$/i,
|
|
15
|
+
/^Ellipse \d+$/i,
|
|
16
|
+
/^Line \d+$/i,
|
|
17
|
+
/^Group \d+$/i,
|
|
18
|
+
/^Vector \d+$/i,
|
|
19
|
+
/^Text$/i,
|
|
20
|
+
/^Image \d*$/i,
|
|
21
|
+
/^Component \d+$/i,
|
|
22
|
+
/^Instance$/i,
|
|
23
|
+
/^Polygon \d+$/i,
|
|
24
|
+
/^Star \d+$/i,
|
|
25
|
+
/^Boolean \d+$/i,
|
|
26
|
+
];
|
|
27
|
+
// =============================================================================
|
|
28
|
+
// Rule Implementations
|
|
29
|
+
// =============================================================================
|
|
30
|
+
/**
|
|
31
|
+
* Check for generic layer names
|
|
32
|
+
*/
|
|
33
|
+
function checkLayerNaming(node, _context, path) {
|
|
34
|
+
const issues = [];
|
|
35
|
+
const isGeneric = GENERIC_NAMES.some((pattern) => pattern.test(node.name));
|
|
36
|
+
if (isGeneric) {
|
|
37
|
+
issues.push(createIssue('layer-naming', 'info', `Generic layer name "${node.name}" - consider using a descriptive name`, node, path, { suggestion: 'Rename to describe the layer\'s purpose (e.g., "Hero Section", "Primary Button")' }));
|
|
38
|
+
}
|
|
39
|
+
return issues;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check for missing auto-layout on frames with multiple children
|
|
43
|
+
*/
|
|
44
|
+
function checkMissingAutoLayout(node, _context, path) {
|
|
45
|
+
const issues = [];
|
|
46
|
+
// Only check frames
|
|
47
|
+
if (node.type !== 'FRAME' && node.type !== 'COMPONENT') {
|
|
48
|
+
return issues;
|
|
49
|
+
}
|
|
50
|
+
// Check if it has children but no auto-layout
|
|
51
|
+
const childCount = node.children?.length ?? 0;
|
|
52
|
+
if (childCount >= 2 && !node.hasAutoLayout) {
|
|
53
|
+
issues.push(createIssue('missing-autolayout', 'info', `Frame "${node.name}" has ${childCount} children but no auto-layout`, node, path, { suggestion: 'Consider adding auto-layout for responsive design' }));
|
|
54
|
+
}
|
|
55
|
+
return issues;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check naming conventions
|
|
59
|
+
*/
|
|
60
|
+
function checkNamingConvention(node, _context, path) {
|
|
61
|
+
const issues = [];
|
|
62
|
+
// Check components follow PascalCase
|
|
63
|
+
if (node.type === 'COMPONENT' || node.type === 'COMPONENT_SET') {
|
|
64
|
+
const isPascalCase = /^[A-Z][a-zA-Z0-9]*(\s[A-Z][a-zA-Z0-9]*)*$/.test(node.name);
|
|
65
|
+
if (!isPascalCase && !node.name.includes('/')) {
|
|
66
|
+
issues.push(createIssue('naming-convention', 'info', `Component "${node.name}" doesn't follow PascalCase naming`, node, path, { suggestion: 'Use PascalCase for components (e.g., "PrimaryButton", "Card Header")' }));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Check for very short names (likely meaningless)
|
|
70
|
+
if (node.name.length === 1 && node.type !== 'TEXT') {
|
|
71
|
+
issues.push(createIssue('naming-convention', 'info', `Very short layer name "${node.name}" - likely needs more context`, node, path, { suggestion: 'Use descriptive names that explain the layer\'s purpose' }));
|
|
72
|
+
}
|
|
73
|
+
return issues;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check for potential text overflow issues
|
|
77
|
+
*/
|
|
78
|
+
function checkTextOverflow(node, _context, path) {
|
|
79
|
+
const issues = [];
|
|
80
|
+
// Only check text nodes
|
|
81
|
+
if (node.type !== 'TEXT') {
|
|
82
|
+
return issues;
|
|
83
|
+
}
|
|
84
|
+
// Check for truncated text (indicated by ...)
|
|
85
|
+
if (node.characters && node.characters.endsWith('...')) {
|
|
86
|
+
issues.push(createIssue('text-overflow', 'warning', `Text "${node.name}" may be truncated`, node, path, {
|
|
87
|
+
suggestion: 'Check if text overflow is intentional or if container needs resizing',
|
|
88
|
+
actual: node.characters,
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
return issues;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check component usage (prefer instances over detached)
|
|
95
|
+
*/
|
|
96
|
+
function checkComponentUsage(node, _context, path) {
|
|
97
|
+
const issues = [];
|
|
98
|
+
// Check for frames that might be better as component instances
|
|
99
|
+
if (node.type === 'FRAME' && node.children) {
|
|
100
|
+
// Look for patterns that suggest this should be a component
|
|
101
|
+
const childNames = node.children.map((c) => c.name);
|
|
102
|
+
const hasButtonPattern = childNames.some((n) => /button|btn|cta/i.test(n));
|
|
103
|
+
const hasCardPattern = childNames.some((n) => /title|description|image|content/i.test(n));
|
|
104
|
+
if (hasButtonPattern || hasCardPattern) {
|
|
105
|
+
// Check if parent path suggests this is already a component
|
|
106
|
+
const isComponent = path.some((p) => /component|instance/i.test(p));
|
|
107
|
+
if (!isComponent && !node.componentKey) {
|
|
108
|
+
issues.push(createIssue('component-usage', 'info', `Frame "${node.name}" has common component patterns - consider making it a component`, node, path, { suggestion: 'Convert to component for reusability and consistency' }));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return issues;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Check spacing consistency (basic check for common values)
|
|
116
|
+
*/
|
|
117
|
+
function checkSpacingConsistency(_node, _context, _path) {
|
|
118
|
+
// This is a simplified check - full implementation would need
|
|
119
|
+
// actual spacing values from the Figma API
|
|
120
|
+
// For MVP, we just note frames without auto-layout padding
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Check font consistency
|
|
125
|
+
*/
|
|
126
|
+
function checkFontConsistency(_node, _context, _path) {
|
|
127
|
+
// Font consistency requires style information from the API
|
|
128
|
+
// For MVP, this is a placeholder
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Check token usage
|
|
133
|
+
*/
|
|
134
|
+
function checkTokenUsage(_node, _context, _path) {
|
|
135
|
+
// Token usage requires variable bindings from the API
|
|
136
|
+
// For MVP, this is a placeholder
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Check color contrast
|
|
141
|
+
*/
|
|
142
|
+
function checkColorContrast(_node, _context, _path) {
|
|
143
|
+
// Color contrast requires color values from the API
|
|
144
|
+
// For MVP, this is a placeholder
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Check image resolution
|
|
149
|
+
*/
|
|
150
|
+
function checkImageResolution(_node, _context, _path) {
|
|
151
|
+
// Image resolution requires image API calls
|
|
152
|
+
// Disabled by default
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
// =============================================================================
|
|
156
|
+
// Rule Registry
|
|
157
|
+
// =============================================================================
|
|
158
|
+
const RULE_CHECKERS = {
|
|
159
|
+
'layer-naming': checkLayerNaming,
|
|
160
|
+
'missing-autolayout': checkMissingAutoLayout,
|
|
161
|
+
'naming-convention': checkNamingConvention,
|
|
162
|
+
'text-overflow': checkTextOverflow,
|
|
163
|
+
'component-usage': checkComponentUsage,
|
|
164
|
+
'spacing-consistency': checkSpacingConsistency,
|
|
165
|
+
'font-consistency': checkFontConsistency,
|
|
166
|
+
'token-usage': checkTokenUsage,
|
|
167
|
+
'color-contrast': checkColorContrast,
|
|
168
|
+
'image-resolution': checkImageResolution,
|
|
169
|
+
};
|
|
170
|
+
// =============================================================================
|
|
171
|
+
// Helper Functions
|
|
172
|
+
// =============================================================================
|
|
173
|
+
function createIssue(ruleId, severity, message, node, path, extras = {}) {
|
|
174
|
+
return {
|
|
175
|
+
ruleId,
|
|
176
|
+
severity,
|
|
177
|
+
message,
|
|
178
|
+
location: {
|
|
179
|
+
nodeId: node.id,
|
|
180
|
+
nodeName: node.name,
|
|
181
|
+
nodePath: path.join(' > '),
|
|
182
|
+
nodeType: node.type,
|
|
183
|
+
},
|
|
184
|
+
...extras,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function getEnabledRules(config) {
|
|
188
|
+
// Import DEFAULT_AUDIT_RULES at runtime to avoid circular deps
|
|
189
|
+
const defaultRules = [
|
|
190
|
+
{ id: 'layer-naming', name: 'Layer Naming', description: 'Check for generic layer names', severity: 'info', category: 'naming', enabled: true },
|
|
191
|
+
{ id: 'missing-autolayout', name: 'Missing Auto-Layout', description: 'Identify frames without auto-layout', severity: 'info', category: 'best-practices', enabled: true },
|
|
192
|
+
{ id: 'naming-convention', name: 'Naming Convention', description: 'Check naming conventions', severity: 'info', category: 'naming', enabled: true },
|
|
193
|
+
{ id: 'text-overflow', name: 'Text Overflow', description: 'Detect text overflow issues', severity: 'warning', category: 'best-practices', enabled: true },
|
|
194
|
+
{ id: 'component-usage', name: 'Component Usage', description: 'Check component usage patterns', severity: 'info', category: 'best-practices', enabled: true },
|
|
195
|
+
{ id: 'spacing-consistency', name: 'Spacing Consistency', description: 'Check spacing values', severity: 'warning', category: 'consistency', enabled: true },
|
|
196
|
+
{ id: 'font-consistency', name: 'Font Consistency', description: 'Check font consistency', severity: 'warning', category: 'consistency', enabled: true },
|
|
197
|
+
{ id: 'token-usage', name: 'Token Usage', description: 'Check token usage', severity: 'warning', category: 'consistency', enabled: true },
|
|
198
|
+
{ id: 'color-contrast', name: 'Color Contrast', description: 'Check color contrast', severity: 'error', category: 'accessibility', enabled: true },
|
|
199
|
+
{ id: 'image-resolution', name: 'Image Resolution', description: 'Check image resolution', severity: 'warning', category: 'performance', enabled: false },
|
|
200
|
+
];
|
|
201
|
+
let rules = [...defaultRules];
|
|
202
|
+
// Filter to only requested rules
|
|
203
|
+
if (config.rules && config.rules.length > 0) {
|
|
204
|
+
rules = rules.filter((r) => config.rules.includes(r.id));
|
|
205
|
+
}
|
|
206
|
+
// Exclude specified rules
|
|
207
|
+
if (config.excludeRules && config.excludeRules.length > 0) {
|
|
208
|
+
rules = rules.filter((r) => !config.excludeRules.includes(r.id));
|
|
209
|
+
}
|
|
210
|
+
// Apply rule overrides
|
|
211
|
+
if (config.ruleConfig) {
|
|
212
|
+
rules = rules.map((rule) => {
|
|
213
|
+
const override = config.ruleConfig?.[rule.id];
|
|
214
|
+
if (override) {
|
|
215
|
+
return {
|
|
216
|
+
...rule,
|
|
217
|
+
enabled: override.enabled ?? rule.enabled,
|
|
218
|
+
severity: override.severity ?? rule.severity,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return rule;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
// Return only enabled rules
|
|
225
|
+
return rules.filter((r) => r.enabled);
|
|
226
|
+
}
|
|
227
|
+
// =============================================================================
|
|
228
|
+
// Main Audit Function
|
|
229
|
+
// =============================================================================
|
|
230
|
+
/**
|
|
231
|
+
* Audit a Figma file/node for design issues
|
|
232
|
+
*/
|
|
233
|
+
export function auditDesign(mapResult, config = {}) {
|
|
234
|
+
const startTime = Date.now();
|
|
235
|
+
const enabledRules = getEnabledRules(config);
|
|
236
|
+
const context = {
|
|
237
|
+
fileKey: mapResult.fileKey,
|
|
238
|
+
fileName: mapResult.fileName,
|
|
239
|
+
config,
|
|
240
|
+
rules: enabledRules,
|
|
241
|
+
issues: [],
|
|
242
|
+
nodesAudited: 0,
|
|
243
|
+
startTime,
|
|
244
|
+
};
|
|
245
|
+
// Traverse and audit
|
|
246
|
+
auditNode(mapResult.root, context, [], 0);
|
|
247
|
+
// Build summary
|
|
248
|
+
const issueCount = {
|
|
249
|
+
error: context.issues.filter((i) => i.severity === 'error').length,
|
|
250
|
+
warning: context.issues.filter((i) => i.severity === 'warning').length,
|
|
251
|
+
info: context.issues.filter((i) => i.severity === 'info').length,
|
|
252
|
+
total: context.issues.length,
|
|
253
|
+
};
|
|
254
|
+
const summary = {
|
|
255
|
+
totalNodes: mapResult.nodeCount,
|
|
256
|
+
nodesAudited: context.nodesAudited,
|
|
257
|
+
issueCount,
|
|
258
|
+
passRate: context.nodesAudited > 0
|
|
259
|
+
? Math.round(((context.nodesAudited - issueCount.total) / context.nodesAudited) * 100 * 100) / 100
|
|
260
|
+
: 100,
|
|
261
|
+
rulesRun: enabledRules.map((r) => r.id),
|
|
262
|
+
duration: Date.now() - startTime,
|
|
263
|
+
};
|
|
264
|
+
return {
|
|
265
|
+
fileKey: mapResult.fileKey,
|
|
266
|
+
fileName: mapResult.fileName,
|
|
267
|
+
timestamp: new Date().toISOString(),
|
|
268
|
+
summary,
|
|
269
|
+
issues: context.issues,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Recursively audit a node and its children
|
|
274
|
+
*/
|
|
275
|
+
function auditNode(node, context, path, depth) {
|
|
276
|
+
// Check depth limit
|
|
277
|
+
if (context.config.maxDepth !== undefined && depth > context.config.maxDepth) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
context.nodesAudited++;
|
|
281
|
+
const currentPath = [...path, node.name];
|
|
282
|
+
// Run each enabled rule
|
|
283
|
+
for (const rule of context.rules) {
|
|
284
|
+
const checker = RULE_CHECKERS[rule.id];
|
|
285
|
+
if (checker) {
|
|
286
|
+
const issues = checker(node, context, currentPath);
|
|
287
|
+
// Apply rule severity override
|
|
288
|
+
const processedIssues = issues.map((issue) => ({
|
|
289
|
+
...issue,
|
|
290
|
+
severity: rule.severity, // Use rule's severity (may be overridden)
|
|
291
|
+
}));
|
|
292
|
+
context.issues.push(...processedIssues);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
// Recurse into children
|
|
296
|
+
if (node.children) {
|
|
297
|
+
for (const child of node.children) {
|
|
298
|
+
auditNode(child, context, currentPath, depth + 1);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// =============================================================================
|
|
303
|
+
// Output Formatting
|
|
304
|
+
// =============================================================================
|
|
305
|
+
/**
|
|
306
|
+
* Format audit result for terminal display
|
|
307
|
+
*/
|
|
308
|
+
export function formatAuditResult(result) {
|
|
309
|
+
const lines = [];
|
|
310
|
+
// Header
|
|
311
|
+
lines.push('Design Audit Report');
|
|
312
|
+
lines.push('===================');
|
|
313
|
+
lines.push(`File: ${result.fileName ?? result.fileKey}`);
|
|
314
|
+
lines.push(`Timestamp: ${result.timestamp}`);
|
|
315
|
+
lines.push('');
|
|
316
|
+
// Summary
|
|
317
|
+
lines.push('Summary');
|
|
318
|
+
lines.push('-------');
|
|
319
|
+
lines.push(`Nodes audited: ${result.summary.nodesAudited}/${result.summary.totalNodes}`);
|
|
320
|
+
lines.push(`Rules run: ${result.summary.rulesRun.length}`);
|
|
321
|
+
lines.push(`Duration: ${result.summary.duration}ms`);
|
|
322
|
+
lines.push('');
|
|
323
|
+
lines.push(`Issues: ${result.summary.issueCount.total}`);
|
|
324
|
+
lines.push(` Errors: ${result.summary.issueCount.error}`);
|
|
325
|
+
lines.push(` Warnings: ${result.summary.issueCount.warning}`);
|
|
326
|
+
lines.push(` Info: ${result.summary.issueCount.info}`);
|
|
327
|
+
lines.push('');
|
|
328
|
+
lines.push(`Pass Rate: ${result.summary.passRate}%`);
|
|
329
|
+
lines.push('');
|
|
330
|
+
// Issues by severity
|
|
331
|
+
if (result.issues.length > 0) {
|
|
332
|
+
lines.push('Issues');
|
|
333
|
+
lines.push('------');
|
|
334
|
+
// Group by severity
|
|
335
|
+
const byRule = new Map();
|
|
336
|
+
for (const issue of result.issues) {
|
|
337
|
+
const existing = byRule.get(issue.ruleId) ?? [];
|
|
338
|
+
existing.push(issue);
|
|
339
|
+
byRule.set(issue.ruleId, existing);
|
|
340
|
+
}
|
|
341
|
+
for (const [ruleId, issues] of byRule) {
|
|
342
|
+
lines.push('');
|
|
343
|
+
lines.push(`[${ruleId}] (${issues.length} issue${issues.length === 1 ? '' : 's'})`);
|
|
344
|
+
for (const issue of issues.slice(0, 10)) {
|
|
345
|
+
const severityIcon = issue.severity === 'error' ? '✗' : issue.severity === 'warning' ? '!' : '•';
|
|
346
|
+
lines.push(` ${severityIcon} ${issue.message}`);
|
|
347
|
+
lines.push(` Path: ${issue.location.nodePath}`);
|
|
348
|
+
lines.push(` Node ID: ${issue.location.nodeId}`);
|
|
349
|
+
if (issue.suggestion) {
|
|
350
|
+
lines.push(` Suggestion: ${issue.suggestion}`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (issues.length > 10) {
|
|
354
|
+
lines.push(` ... and ${issues.length - 10} more`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
lines.push('No issues found!');
|
|
360
|
+
}
|
|
361
|
+
return lines.join('\n');
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Format audit result as compact summary
|
|
365
|
+
*/
|
|
366
|
+
export function formatAuditSummary(result) {
|
|
367
|
+
const { summary } = result;
|
|
368
|
+
const status = summary.issueCount.error > 0
|
|
369
|
+
? 'FAILED'
|
|
370
|
+
: summary.issueCount.warning > 0
|
|
371
|
+
? 'WARNINGS'
|
|
372
|
+
: 'PASSED';
|
|
373
|
+
return `[${status}] ${summary.nodesAudited} nodes, ${summary.issueCount.total} issues (${summary.issueCount.error} errors, ${summary.issueCount.warning} warnings, ${summary.issueCount.info} info) - ${summary.passRate}% pass rate`;
|
|
374
|
+
}
|
|
375
|
+
//# sourceMappingURL=figma-audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figma-audit.js","sourceRoot":"","sources":["../../src/design/figma-audit.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA+CH,gFAAgF;AAChF,gCAAgC;AAChC,gFAAgF;AAEhF,MAAM,aAAa,GAAG;IACpB,cAAc;IACd,kBAAkB;IAClB,gBAAgB;IAChB,aAAa;IACb,cAAc;IACd,eAAe;IACf,SAAS;IACT,cAAc;IACd,kBAAkB;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ACZ,CAAC,CAAC,QAAQ,CAAC;IAEf,OAAO,IAAI,MAAM,KAAK,OAAO,CAAC,YAAY,WAAW,OAAO,CAAC,UAAU,CAAC,KAAK,YAAY,OAAO,CAAC,UAAU,CAAC,KAAK,YAAY,OAAO,CAAC,UAAU,CAAC,OAAO,cAAc,OAAO,CAAC,UAAU,CAAC,IAAI,YAAY,OAAO,CAAC,QAAQ,aAAa,CAAC;AACxO,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Figma REST API Client
|
|
3
|
+
*
|
|
4
|
+
* Provides a type-safe interface to the Figma REST API.
|
|
5
|
+
* Includes caching, rate limiting, and error handling.
|
|
6
|
+
*
|
|
7
|
+
* @module design/figma-client
|
|
8
|
+
*/
|
|
9
|
+
import { type FigmaFileResponse, type FigmaNodesResponse, type FigmaVariablesResponse, type FigmaImagesResponse, type GetFileOptions, type GetImagesOptions } from '@ax-cli/schemas';
|
|
10
|
+
export interface FigmaClientConfig {
|
|
11
|
+
/** Figma API access token */
|
|
12
|
+
accessToken: string;
|
|
13
|
+
/** Base URL for Figma API (default: https://api.figma.com) */
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
/** Request timeout in ms (default: 30000) */
|
|
16
|
+
timeout?: number;
|
|
17
|
+
/** Enable response caching (default: true) */
|
|
18
|
+
cacheEnabled?: boolean;
|
|
19
|
+
/** Cache TTL in ms (default: 60000) */
|
|
20
|
+
cacheTtl?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface FigmaApiError extends Error {
|
|
23
|
+
status: number;
|
|
24
|
+
endpoint: string;
|
|
25
|
+
figmaError?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare class FigmaClient {
|
|
28
|
+
private readonly accessToken;
|
|
29
|
+
private readonly baseUrl;
|
|
30
|
+
private readonly timeout;
|
|
31
|
+
private readonly cache;
|
|
32
|
+
private readonly cacheEnabled;
|
|
33
|
+
private readonly rateLimiter;
|
|
34
|
+
constructor(config: FigmaClientConfig);
|
|
35
|
+
private request;
|
|
36
|
+
/**
|
|
37
|
+
* Get a Figma file
|
|
38
|
+
*
|
|
39
|
+
* @param fileKey - The file key from the Figma URL
|
|
40
|
+
* @param options - Optional parameters (depth, geometry, etc.)
|
|
41
|
+
* @returns Validated FigmaFileResponse
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const file = await client.getFile('abc123xyz', { depth: 2 });
|
|
46
|
+
* console.log(file.name);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
getFile(fileKey: string, options?: GetFileOptions): Promise<FigmaFileResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Get specific nodes from a Figma file
|
|
52
|
+
*
|
|
53
|
+
* @param fileKey - The file key from the Figma URL
|
|
54
|
+
* @param nodeIds - Array of node IDs to fetch
|
|
55
|
+
* @returns Validated FigmaNodesResponse
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const nodes = await client.getFileNodes('abc123xyz', ['1:2', '3:4']);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
getFileNodes(fileKey: string, nodeIds: string[]): Promise<FigmaNodesResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* Get local variables (design tokens) from a Figma file
|
|
65
|
+
*
|
|
66
|
+
* @param fileKey - The file key from the Figma URL
|
|
67
|
+
* @returns Validated FigmaVariablesResponse
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const variables = await client.getLocalVariables('abc123xyz');
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
getLocalVariables(fileKey: string): Promise<FigmaVariablesResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Get images for specific nodes
|
|
77
|
+
*
|
|
78
|
+
* @param fileKey - The file key from the Figma URL
|
|
79
|
+
* @param nodeIds - Array of node IDs to export
|
|
80
|
+
* @param options - Export options (scale, format)
|
|
81
|
+
* @returns Validated FigmaImagesResponse with URLs
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const images = await client.getImages('abc123xyz', ['1:2'], { format: 'png', scale: 2 });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
getImages(fileKey: string, nodeIds: string[], options?: GetImagesOptions): Promise<FigmaImagesResponse>;
|
|
89
|
+
/**
|
|
90
|
+
* Get file metadata without the full document tree
|
|
91
|
+
*
|
|
92
|
+
* @param fileKey - The file key from the Figma URL
|
|
93
|
+
* @returns Basic file info (name, lastModified, etc.)
|
|
94
|
+
*/
|
|
95
|
+
getFileMetadata(fileKey: string): Promise<{
|
|
96
|
+
name: string;
|
|
97
|
+
lastModified: string;
|
|
98
|
+
version: string;
|
|
99
|
+
thumbnailUrl?: string;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Clear the response cache
|
|
103
|
+
*/
|
|
104
|
+
clearCache(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Invalidate cache for a specific file
|
|
107
|
+
*/
|
|
108
|
+
invalidateFile(fileKey: string): void;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Create a new Figma client instance
|
|
112
|
+
*/
|
|
113
|
+
export declare function createFigmaClient(config: FigmaClientConfig): FigmaClient;
|
|
114
|
+
/**
|
|
115
|
+
* Get the default Figma client (creates one if needed)
|
|
116
|
+
*
|
|
117
|
+
* Uses FIGMA_ACCESS_TOKEN environment variable if no token provided.
|
|
118
|
+
*/
|
|
119
|
+
export declare function getFigmaClient(accessToken?: string): FigmaClient;
|
|
120
|
+
/**
|
|
121
|
+
* Reset the default client (useful for testing)
|
|
122
|
+
*/
|
|
123
|
+
export declare function resetFigmaClient(): void;
|