@sloppy-ai/cli 0.0.0-stage → 1.1.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/bin/sloppy.js +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1567 -0
- package/dist/index.js.map +1 -0
- package/package.json +32 -4
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,1567 @@
|
|
|
1
|
+
import { auditCode, AUTO_FIX_RULE_TYPES, CANONICAL_RULES, RULE_METADATA, createRepairPlan, DESIGN_MD_TEMPLATE, detectProjectStack, evaluateCraftRubric, extractDesignDna, getComponentById, getNextMaterial, getPatternById, getSynthesizedArchetype, loadSloppyConfig, resolveDesignContract, LOOKS, MOTION_ECOSYSTEMS, PATTERNS_CATALOG, SLOPPY_COMPONENTS, SLOPPY_LIBRARIES, SYNTHESIZED_ARCHETYPES, transformSlopToCraft } from '@sloppy-ai/core';
|
|
2
|
+
import { runServer } from '@sloppy-ai/mcp';
|
|
3
|
+
import { execFileSync, spawn } from 'child_process';
|
|
4
|
+
import { createHash } from 'crypto';
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { createRequire } from 'module';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
const ROOT_DIR = path.resolve(__dirname, '../../../');
|
|
12
|
+
const PATTERNS_DIR = path.resolve(ROOT_DIR, 'patterns');
|
|
13
|
+
const KIT_DIR = path.resolve(ROOT_DIR, 'packages/kit');
|
|
14
|
+
const COMPONENTS_DIR = path.resolve(ROOT_DIR, 'packages/components');
|
|
15
|
+
const PLAYGROUND_DIR = path.resolve(ROOT_DIR, 'packages/playground');
|
|
16
|
+
const sourceExtensions = /\.(tsx|jsx|ts|js|html|css)$/i;
|
|
17
|
+
const severities = ['low', 'medium', 'high', 'critical'];
|
|
18
|
+
const gradeOrder = ['F', 'D', 'C', 'B', 'A', 'A+'];
|
|
19
|
+
const require = createRequire(import.meta.url);
|
|
20
|
+
function emitJson(value) { process.stdout.write(`${JSON.stringify(value)}\n`); }
|
|
21
|
+
function fail(message, code = 2) { console.error(message); process.exitCode = code; }
|
|
22
|
+
function surfaceType(args) {
|
|
23
|
+
const value = args.includes('--type') ? args[args.indexOf('--type') + 1] : undefined;
|
|
24
|
+
return ['illustration', 'feature-card', 'hero', 'application', 'bento'].includes(value || '') ? value : undefined;
|
|
25
|
+
}
|
|
26
|
+
function cliVersion() {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8')).version;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(fs.readFileSync(path.resolve(ROOT_DIR, 'packages/cli/package.json'), 'utf8')).version;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return '1.0.0';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function readOptionalFile(filePath) {
|
|
40
|
+
try {
|
|
41
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if (err?.code === 'ENOENT')
|
|
45
|
+
return null;
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function writeFileSafe(filePath, data, overwrite) {
|
|
50
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
51
|
+
if (overwrite) {
|
|
52
|
+
fs.writeFileSync(filePath, data, 'utf8');
|
|
53
|
+
return 'written';
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
fs.writeFileSync(filePath, data, { encoding: 'utf8', flag: 'wx' });
|
|
57
|
+
return 'created';
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
if (err?.code === 'EEXIST')
|
|
61
|
+
return 'exists';
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function createDirContextResolver() {
|
|
66
|
+
const dirCache = new Map();
|
|
67
|
+
return (filePath) => {
|
|
68
|
+
const dir = path.dirname(path.resolve(filePath));
|
|
69
|
+
const hit = dirCache.get(dir);
|
|
70
|
+
if (hit)
|
|
71
|
+
return hit;
|
|
72
|
+
const config = loadSloppyConfig(dir);
|
|
73
|
+
const designContract = resolveDesignContract(dir, config);
|
|
74
|
+
const resolved = {
|
|
75
|
+
config,
|
|
76
|
+
designContract,
|
|
77
|
+
signature: JSON.stringify({ config, designContract })
|
|
78
|
+
};
|
|
79
|
+
dirCache.set(dir, resolved);
|
|
80
|
+
return resolved;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function collectGitChangedFiles(mode, targets) {
|
|
84
|
+
const roots = (targets.length ? targets : ['.']).map(t => path.resolve(process.cwd(), t));
|
|
85
|
+
const raw = new Set();
|
|
86
|
+
try {
|
|
87
|
+
if (mode === 'staged') {
|
|
88
|
+
const out = execFileSync('git', ['diff', '--cached', '--name-only', '--diff-filter=ACMR', '-z'], { encoding: 'utf8' });
|
|
89
|
+
for (const f of out.split('\0'))
|
|
90
|
+
if (f)
|
|
91
|
+
raw.add(path.resolve(process.cwd(), f));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const tracked = execFileSync('git', ['diff', '--name-only', '--diff-filter=ACMR', 'HEAD', '-z'], { encoding: 'utf8' });
|
|
95
|
+
const untracked = execFileSync('git', ['ls-files', '--others', '--exclude-standard', '-z'], { encoding: 'utf8' });
|
|
96
|
+
for (const f of `${tracked}\0${untracked}`.split('\0'))
|
|
97
|
+
if (f)
|
|
98
|
+
raw.add(path.resolve(process.cwd(), f));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return collectFiles(targets.length ? targets : ['.']);
|
|
103
|
+
}
|
|
104
|
+
return [...raw]
|
|
105
|
+
.filter(f => sourceExtensions.test(f) && roots.some(r => f === r || f.startsWith(`${r}${path.sep}`)))
|
|
106
|
+
.filter(f => { try {
|
|
107
|
+
return fs.statSync(f).isFile();
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
} })
|
|
112
|
+
.sort();
|
|
113
|
+
}
|
|
114
|
+
const CACHE_FILE = path.resolve(process.cwd(), '.sloppy/cache.json');
|
|
115
|
+
function loadScanCache(enabled) {
|
|
116
|
+
if (!enabled)
|
|
117
|
+
return {};
|
|
118
|
+
const raw = readOptionalFile(CACHE_FILE);
|
|
119
|
+
if (!raw)
|
|
120
|
+
return {};
|
|
121
|
+
try {
|
|
122
|
+
const parsed = JSON.parse(raw);
|
|
123
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return {};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function saveScanCache(enabled, cache) {
|
|
130
|
+
if (!enabled)
|
|
131
|
+
return;
|
|
132
|
+
try {
|
|
133
|
+
fs.mkdirSync(path.dirname(CACHE_FILE), { recursive: true });
|
|
134
|
+
fs.writeFileSync(CACHE_FILE, JSON.stringify(cache), 'utf8');
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// Cache persistence failures must never fail linting
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function collectFiles(targets) {
|
|
141
|
+
const found = [];
|
|
142
|
+
const visit = (file, isSubEntry = false) => {
|
|
143
|
+
if (isSubEntry && fs.lstatSync(file).isSymbolicLink())
|
|
144
|
+
return;
|
|
145
|
+
const stat = fs.statSync(file);
|
|
146
|
+
if (stat.isDirectory()) {
|
|
147
|
+
for (const entry of fs.readdirSync(file).sort()) {
|
|
148
|
+
if (['node_modules', '.git', 'dist'].includes(entry))
|
|
149
|
+
continue;
|
|
150
|
+
visit(path.join(file, entry), true);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else if (stat.isFile() && sourceExtensions.test(file))
|
|
154
|
+
found.push(file);
|
|
155
|
+
};
|
|
156
|
+
for (const target of targets)
|
|
157
|
+
visit(path.resolve(process.cwd(), target));
|
|
158
|
+
return [...new Set(found)].sort();
|
|
159
|
+
}
|
|
160
|
+
function formatSarif(result) {
|
|
161
|
+
return {
|
|
162
|
+
$schema: 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json',
|
|
163
|
+
version: '2.1.0',
|
|
164
|
+
runs: [
|
|
165
|
+
{
|
|
166
|
+
tool: {
|
|
167
|
+
driver: {
|
|
168
|
+
name: 'Sloppy',
|
|
169
|
+
version: result.version,
|
|
170
|
+
informationUri: 'https://github.com/Pavanspoojary/sloppy',
|
|
171
|
+
rules: Object.entries(CANONICAL_RULES).map(([slug, rule]) => ({
|
|
172
|
+
id: slug,
|
|
173
|
+
name: rule.title.replace(/[^A-Za-z0-9]/g, ''),
|
|
174
|
+
shortDescription: { text: `${rule.ruleId}: ${rule.title}` }
|
|
175
|
+
}))
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
results: result.files.flatMap(f => f.violations.map(v => ({
|
|
179
|
+
ruleId: v.type,
|
|
180
|
+
level: (v.severity === 'critical' || v.severity === 'high') ? 'error' : 'warning',
|
|
181
|
+
message: { text: `${v.message} ${v.recommendation}` },
|
|
182
|
+
locations: [
|
|
183
|
+
{
|
|
184
|
+
physicalLocation: {
|
|
185
|
+
artifactLocation: { uri: f.path },
|
|
186
|
+
region: { startLine: v.line, startColumn: v.column }
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
})))
|
|
191
|
+
}
|
|
192
|
+
]
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function checkFiles(paths, options) {
|
|
196
|
+
const version = cliVersion();
|
|
197
|
+
const resolveContext = createDirContextResolver();
|
|
198
|
+
const cacheEnabled = Boolean(options.cache);
|
|
199
|
+
const scanCache = loadScanCache(cacheEnabled);
|
|
200
|
+
const nextCache = cacheEnabled ? { ...scanCache } : {};
|
|
201
|
+
let cacheDirty = false;
|
|
202
|
+
const optSignature = JSON.stringify({ maxScore: options.maxScore, failOn: options.failOn, minGrade: options.minGrade, type: options.type, codeOnly: options.codeOnly, strict: options.strict, version });
|
|
203
|
+
const files = paths.map(file => {
|
|
204
|
+
const code = fs.readFileSync(file, 'utf8');
|
|
205
|
+
const relative = path.relative(process.cwd(), file) || file;
|
|
206
|
+
const ctx = resolveContext(file);
|
|
207
|
+
let contentHash = '';
|
|
208
|
+
if (cacheEnabled) {
|
|
209
|
+
contentHash = createHash('sha256').update(optSignature).update(ctx.signature).update(code).digest('hex');
|
|
210
|
+
const cached = scanCache[`check:${relative}`];
|
|
211
|
+
if (cached && cached.hash === contentHash && cached.entry && typeof cached.entry === 'object') {
|
|
212
|
+
return cached.entry;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const audit = auditCode(code, {
|
|
216
|
+
filepath: relative,
|
|
217
|
+
componentType: options.type,
|
|
218
|
+
codeOnly: options.codeOnly,
|
|
219
|
+
strict: options.strict,
|
|
220
|
+
config: ctx.config ?? undefined,
|
|
221
|
+
designContract: ctx.designContract
|
|
222
|
+
});
|
|
223
|
+
const rubric = evaluateCraftRubric(code, { filepath: relative, componentType: options.type, strict: options.strict, audit });
|
|
224
|
+
const violations = audit.violations.map(v => ({
|
|
225
|
+
id: v.id,
|
|
226
|
+
type: v.type,
|
|
227
|
+
severity: v.severity,
|
|
228
|
+
line: v.line || 1,
|
|
229
|
+
column: v.column || 1,
|
|
230
|
+
snippet: v.snippet || '',
|
|
231
|
+
message: v.message,
|
|
232
|
+
recommendation: v.recommendation,
|
|
233
|
+
confidence: v.confidence,
|
|
234
|
+
objective: v.objective,
|
|
235
|
+
evidence: v.evidence
|
|
236
|
+
}));
|
|
237
|
+
const entry = { path: relative, score: audit.slopScore, grade: rubric.grade, isSlopFree: audit.isSlopFree, words: audit.stats.estimatedWordCount, suppressed: audit.stats.suppressedCount ?? 0, violations };
|
|
238
|
+
if (cacheEnabled) {
|
|
239
|
+
nextCache[`check:${relative}`] = { hash: contentHash, entry };
|
|
240
|
+
cacheDirty = true;
|
|
241
|
+
}
|
|
242
|
+
return entry;
|
|
243
|
+
});
|
|
244
|
+
if (cacheDirty)
|
|
245
|
+
saveScanCache(cacheEnabled, nextCache);
|
|
246
|
+
const bySeverity = { critical: 0, high: 0, medium: 0, low: 0 };
|
|
247
|
+
let objectiveCount = 0;
|
|
248
|
+
let craftCount = 0;
|
|
249
|
+
for (const file of files)
|
|
250
|
+
for (const v of file.violations) {
|
|
251
|
+
bySeverity[v.severity]++;
|
|
252
|
+
if (v.objective)
|
|
253
|
+
objectiveCount++;
|
|
254
|
+
else
|
|
255
|
+
craftCount++;
|
|
256
|
+
}
|
|
257
|
+
const score = files.reduce((peak, f) => Math.max(peak, f.score), 0);
|
|
258
|
+
const grade = files.reduce((worst, f) => gradeOrder.indexOf(f.grade) < gradeOrder.indexOf(worst) ? f.grade : worst, 'A+');
|
|
259
|
+
const threshold = options.failOn === 'none' ? -1 : severities.indexOf(options.failOn);
|
|
260
|
+
const violations = files.reduce((sum, f) => sum + f.violations.length, 0);
|
|
261
|
+
const gradeFailed = options.minGrade ? gradeOrder.indexOf(grade) < gradeOrder.indexOf(options.minGrade) : false;
|
|
262
|
+
const ok = files.every(f => f.score <= options.maxScore) && !files.some(f => f.violations.some(v => severities.indexOf(v.severity) >= threshold && threshold >= 0)) && !gradeFailed;
|
|
263
|
+
const firstBad = files.find(f => f.violations.length > 0);
|
|
264
|
+
const nextActions = firstBad ? [`Run: sloppy fix ${firstBad.path} --diff`, `Re-run: sloppy check ${firstBad.path}`] : [];
|
|
265
|
+
return { version, ok, score, grade, totals: { files: files.length, violations, objective: objectiveCount, craft: craftCount, bySeverity }, files, nextActions };
|
|
266
|
+
}
|
|
267
|
+
async function handleAgentCommand(command, args) {
|
|
268
|
+
const json = args.includes('--json');
|
|
269
|
+
if (command === '--version' || command === 'version') {
|
|
270
|
+
const version = cliVersion();
|
|
271
|
+
let core;
|
|
272
|
+
try {
|
|
273
|
+
core = require('@sloppy-ai/core/package.json').version;
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
try {
|
|
277
|
+
core = require('@sloppy/core/package.json').version;
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
try {
|
|
281
|
+
core = JSON.parse(fs.readFileSync(path.resolve(ROOT_DIR, 'packages/core/package.json'), 'utf8')).version;
|
|
282
|
+
}
|
|
283
|
+
catch { }
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (json) {
|
|
287
|
+
const payload = { version };
|
|
288
|
+
if (core)
|
|
289
|
+
payload.core = core;
|
|
290
|
+
emitJson(payload);
|
|
291
|
+
}
|
|
292
|
+
else
|
|
293
|
+
console.log(version);
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
if (command === '--help' || (command === 'help' && args.includes('--help'))) {
|
|
297
|
+
console.log('Usage: sloppy <command> [options]\nCommands: setup, check, audit, plan, fix, rubric, verify, install-mcp, rules, version, looks, archetypes, list, mcp');
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
if (command === 'rules') {
|
|
301
|
+
const isCompact = args.includes('--compact');
|
|
302
|
+
const ruleIdx = args.indexOf('--rule');
|
|
303
|
+
const ruleFilter = ruleIdx !== -1 && args[ruleIdx + 1] ? args[ruleIdx + 1].trim().toUpperCase() : undefined;
|
|
304
|
+
const rules = Object.entries(CANONICAL_RULES)
|
|
305
|
+
.filter(([slug, rule]) => !ruleFilter || rule.ruleId.toUpperCase() === ruleFilter || slug.toUpperCase() === ruleFilter)
|
|
306
|
+
.map(([slug, rule]) => isCompact
|
|
307
|
+
? { ruleId: rule.ruleId, slug, tier: rule.tier, mode: rule.mode, defaultSeverity: rule.defaultSeverity, title: rule.title }
|
|
308
|
+
: { slug, ...rule, ...(RULE_METADATA[slug] || {}) })
|
|
309
|
+
.sort((a, b) => a.ruleId.localeCompare(b.ruleId));
|
|
310
|
+
if (json)
|
|
311
|
+
emitJson({ version: cliVersion(), ...(isCompact ? {} : { autoFix: AUTO_FIX_RULE_TYPES }), rules });
|
|
312
|
+
else {
|
|
313
|
+
console.log('\nID SLUG TIER CONF KIND MODE TITLE');
|
|
314
|
+
console.log('----------------------------------------------------------------------------------------------------------------------');
|
|
315
|
+
for (const rule of rules) {
|
|
316
|
+
const meta = RULE_METADATA[rule.slug];
|
|
317
|
+
console.log(`${rule.ruleId.padEnd(8)} ${rule.slug.padEnd(29)} ${rule.tier.padEnd(8)} ${(meta?.confidence || '-').padEnd(8)} ${(meta?.objective ? 'objective' : 'craft').padEnd(10)} ${rule.mode.padEnd(12)} ${rule.title}`);
|
|
318
|
+
}
|
|
319
|
+
console.log('\n"auto-fix" rules are rewritten by `sloppy fix`; "detect-only" rules need a human decision.');
|
|
320
|
+
console.log('"objective" findings are verifiable defects; "craft" findings are contextual judgments. Use `sloppy rules --json` for evidence and false-positive notes.\n');
|
|
321
|
+
}
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
if (args.includes('--help') && ['check', 'fix', 'verify', 'install-mcp', 'setup'].includes(command)) {
|
|
325
|
+
const help = {
|
|
326
|
+
setup: 'Usage: sloppy setup [--write|-w] [--global|-g] [--json]',
|
|
327
|
+
check: 'Usage: sloppy check [paths...|url] [--changed|--staged] [--cache] [--compact] [--strict] [--json] [--max-score <n>] [--fail-on <none|low|medium|high|critical>] [--min-grade <A+|A|B|C|D|F>] [--type <illustration|feature-card|hero|application|bento>] [--render|--multi-width] [--a11y] [--static] [--quiet]',
|
|
328
|
+
fix: 'Usage: sloppy fix <file> [--diff|--check|--write] [--look <look>] [--json]\n sloppy fix --stdin [--json]',
|
|
329
|
+
verify: 'Usage: sloppy verify [target] [--json] [--multi-width] [--a11y] (verification timeout: 15000ms)',
|
|
330
|
+
'install-mcp': 'Usage: sloppy install-mcp --client <cursor|vscode|claude|codex> [--dir <path>] [--write] [--json]'
|
|
331
|
+
};
|
|
332
|
+
console.log(help[command]);
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
if (command === 'check') {
|
|
336
|
+
const isCodeOnly = args.includes('--code') || args.includes('--code-only');
|
|
337
|
+
const isStrict = args.includes('--strict');
|
|
338
|
+
const isChanged = args.includes('--changed');
|
|
339
|
+
const isStaged = args.includes('--staged');
|
|
340
|
+
const useCache = args.includes('--cache') && !args.includes('--no-cache');
|
|
341
|
+
const opts = { maxScore: 0, failOn: 'medium', minGrade: undefined, type: surfaceType(args), codeOnly: isCodeOnly, strict: isStrict, cache: useCache };
|
|
342
|
+
const paths = [];
|
|
343
|
+
for (let i = 0; i < args.length; i++) {
|
|
344
|
+
if (args[i] === '--max-score') {
|
|
345
|
+
opts.maxScore = Number(args[++i]);
|
|
346
|
+
if (!Number.isFinite(opts.maxScore) || opts.maxScore < 0) {
|
|
347
|
+
fail('--max-score must be a non-negative number');
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else if (args[i] === '--fail-on') {
|
|
352
|
+
opts.failOn = args[++i];
|
|
353
|
+
if (!['none', ...severities].includes(opts.failOn)) {
|
|
354
|
+
fail('--fail-on must be none, low, medium, high, or critical');
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
else if (args[i] === '--min-grade') {
|
|
359
|
+
opts.minGrade = args[++i];
|
|
360
|
+
if (!gradeOrder.includes(opts.minGrade)) {
|
|
361
|
+
fail('--min-grade must be A+, A, B, C, D, or F');
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else if (args[i] === '--type') {
|
|
366
|
+
const value = args[++i];
|
|
367
|
+
if (!['illustration', 'feature-card', 'hero', 'application', 'bento'].includes(value)) {
|
|
368
|
+
fail('--type must be illustration, feature-card, hero, application, or bento');
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
else if (args[i] === '--format') {
|
|
373
|
+
const fmt = args[++i];
|
|
374
|
+
if (fmt !== 'sarif' && fmt !== 'json') {
|
|
375
|
+
fail('--format must be sarif or json');
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else if (args[i] === '--sarif' || args[i] === '--watch' || args[i] === '-w' || args[i] === '--code' || args[i] === '--code-only' || args[i] === '--strict' || args[i] === '--compact' || args[i] === '--render' || args[i] === '--multi-width' || args[i] === '--a11y' || args[i] === '--static' || args[i] === '--changed' || args[i] === '--staged' || args[i] === '--cache' || args[i] === '--no-cache') { /* recognized flag */ }
|
|
380
|
+
else if (args[i].startsWith('-')) {
|
|
381
|
+
if (args[i] !== '--json' && args[i] !== '--quiet') {
|
|
382
|
+
fail(`Unknown check option: ${args[i]}`);
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
else
|
|
387
|
+
paths.push(args[i]);
|
|
388
|
+
}
|
|
389
|
+
if (!paths.length && !isChanged && !isStaged) {
|
|
390
|
+
fail('Usage: sloppy check <path...|url> [--changed|--staged] [--cache] [--max-score <n>] [--fail-on <level>] [--min-grade <grade>] [--type <surface>] [--format <json|sarif>] [--render] [--watch]');
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
try {
|
|
394
|
+
const isSarif = args.includes('--sarif') || (args.includes('--format') && args[args.indexOf('--format') + 1] === 'sarif');
|
|
395
|
+
const isWatch = args.includes('--watch') || args.includes('-w');
|
|
396
|
+
const isCompact = args.includes('--compact');
|
|
397
|
+
const wantsRuntime = args.includes('--render') || args.includes('--multi-width');
|
|
398
|
+
const wantsA11y = args.includes('--a11y');
|
|
399
|
+
const runInspection = async () => {
|
|
400
|
+
const urlTargets = paths.filter(p => /^https?:\/\//i.test(p));
|
|
401
|
+
const fileTargets = paths.filter(p => !/^https?:\/\//i.test(p));
|
|
402
|
+
if (!fileTargets.length && !wantsRuntime && !wantsA11y && !isChanged && !isStaged) {
|
|
403
|
+
const message = 'check needs a file path, or a URL together with --render/--a11y';
|
|
404
|
+
if (json)
|
|
405
|
+
emitJson({ version: cliVersion(), ok: false, error: message });
|
|
406
|
+
fail(message);
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
const files = isStaged
|
|
410
|
+
? collectGitChangedFiles('staged', fileTargets)
|
|
411
|
+
: isChanged
|
|
412
|
+
? collectGitChangedFiles('changed', fileTargets)
|
|
413
|
+
: (fileTargets.length ? collectFiles(fileTargets) : []);
|
|
414
|
+
const result = files.length ? checkFiles(files, opts) : {
|
|
415
|
+
version: cliVersion(), ok: true, score: 0, grade: 'A+',
|
|
416
|
+
totals: { files: 0, violations: 0, objective: 0, craft: 0, bySeverity: { critical: 0, high: 0, medium: 0, low: 0 } },
|
|
417
|
+
files: [], nextActions: []
|
|
418
|
+
};
|
|
419
|
+
let runtime = null;
|
|
420
|
+
let accessibility = null;
|
|
421
|
+
let accessibilityUnavailable = false;
|
|
422
|
+
if (wantsRuntime) {
|
|
423
|
+
const target = urlTargets[0] || fileTargets[0];
|
|
424
|
+
const module = await import('@sloppy-ai/verify/multi-width').catch(async () => import(path.resolve(ROOT_DIR, 'packages/verify/multi-width.mjs')));
|
|
425
|
+
const resultRuntime = await module.runMultiWidthVerification(target, { staticOnly: args.includes('--static') });
|
|
426
|
+
runtime = resultRuntime;
|
|
427
|
+
const findings = resultRuntime.findings || [];
|
|
428
|
+
const blocking = findings.filter(f => f.severity === 'critical' || f.severity === 'high').length;
|
|
429
|
+
if (blocking > 0)
|
|
430
|
+
result.ok = false;
|
|
431
|
+
result.totals.violations += findings.length;
|
|
432
|
+
}
|
|
433
|
+
if (wantsA11y) {
|
|
434
|
+
const target = urlTargets[0] || (fileTargets[0] ? path.resolve(fileTargets[0]) : '');
|
|
435
|
+
const module = await import('@sloppy-ai/verify/accessibility').catch(async () => import(path.resolve(ROOT_DIR, 'packages/verify/accessibility.mjs')));
|
|
436
|
+
accessibility = await module.runAccessibilityAudit(target, { timeoutMs: 15000 });
|
|
437
|
+
const findings = accessibility?.findings || [];
|
|
438
|
+
const blocking = findings.filter(f => f.severity === 'critical' || f.severity === 'high').length;
|
|
439
|
+
result.totals.violations += findings.length;
|
|
440
|
+
for (const finding of findings) {
|
|
441
|
+
const severity = finding.severity;
|
|
442
|
+
if (severity in result.totals.bySeverity)
|
|
443
|
+
result.totals.bySeverity[severity] += 1;
|
|
444
|
+
if (finding.objective)
|
|
445
|
+
result.totals.objective += 1;
|
|
446
|
+
else
|
|
447
|
+
result.totals.craft += 1;
|
|
448
|
+
}
|
|
449
|
+
if (blocking)
|
|
450
|
+
result.ok = false;
|
|
451
|
+
if (accessibility?.unavailable) {
|
|
452
|
+
accessibilityUnavailable = true;
|
|
453
|
+
result.ok = false;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
const payload = { ...result, runtime, accessibility };
|
|
457
|
+
if (isSarif)
|
|
458
|
+
emitJson(formatSarif(result));
|
|
459
|
+
else if (json && isCompact) {
|
|
460
|
+
const compactPayload = {
|
|
461
|
+
ok: result.ok,
|
|
462
|
+
score: result.score,
|
|
463
|
+
grade: result.grade,
|
|
464
|
+
totals: result.totals,
|
|
465
|
+
files: result.files.filter(f => f.violations.length > 0).map(f => ({
|
|
466
|
+
path: f.path,
|
|
467
|
+
score: f.score,
|
|
468
|
+
issues: f.violations.map(v => `${v.type}@L${v.line}`)
|
|
469
|
+
}))
|
|
470
|
+
};
|
|
471
|
+
if (runtime)
|
|
472
|
+
compactPayload.runtimeOk = runtime.allPassed;
|
|
473
|
+
if (accessibility)
|
|
474
|
+
compactPayload.a11yOk = accessibility.ok;
|
|
475
|
+
emitJson(compactPayload);
|
|
476
|
+
}
|
|
477
|
+
else if (json)
|
|
478
|
+
emitJson(payload);
|
|
479
|
+
else {
|
|
480
|
+
if (!args.includes('--quiet'))
|
|
481
|
+
for (const f of result.files)
|
|
482
|
+
console.log(`${f.isSlopFree ? 'PASS' : 'FAIL'} ${f.path} score=${f.score} grade=${f.grade} violations=${f.violations.length}`);
|
|
483
|
+
if (runtime) {
|
|
484
|
+
console.log(`\nRuntime ${runtime.isStaticFallback ? '(static source simulation)' : '(headless browser)'}: ${runtime.summary}`);
|
|
485
|
+
for (const f of runtime.findings)
|
|
486
|
+
console.log(` [${f.severity.toUpperCase()}] ${f.viewportName} (${f.width}px): ${f.message}`);
|
|
487
|
+
if (!runtime.findings.length)
|
|
488
|
+
console.log(' contrast and overflow: no rendered defects found');
|
|
489
|
+
}
|
|
490
|
+
if (accessibility) {
|
|
491
|
+
console.log(`\nAccessibility ${accessibility.ok ? 'passed' : accessibility.unavailable ? 'unavailable' : 'failed'} (${accessibility.mode}): ${accessibility.summary}`);
|
|
492
|
+
for (const finding of accessibility.findings)
|
|
493
|
+
console.log(` [${finding.severity.toUpperCase()}] ${finding.rule}: ${finding.message}${finding.evidence?.criterion ? ` (${finding.evidence.criterion})` : ''}`);
|
|
494
|
+
}
|
|
495
|
+
const renderedNote = accessibility?.findings.length ? `, ${accessibility.findings.length} rendered accessibility finding(s)` : '';
|
|
496
|
+
console.log(`Check ${result.ok ? 'passed' : 'failed'}: ${result.totals.files} files, ${result.totals.violations} violations (${result.totals.objective} objective, ${result.totals.craft} craft)${renderedNote}, peak score ${result.score}, worst grade ${result.grade}${runtime ? ', runtime findings included' : ''}`);
|
|
497
|
+
}
|
|
498
|
+
if (accessibilityUnavailable)
|
|
499
|
+
process.exitCode = 2;
|
|
500
|
+
else if (!result.ok)
|
|
501
|
+
process.exitCode = 1;
|
|
502
|
+
return result;
|
|
503
|
+
};
|
|
504
|
+
if (isWatch) {
|
|
505
|
+
console.log(`[SLOPPY WATCH] Watching ${paths.join(', ')} for changes...`);
|
|
506
|
+
await runInspection();
|
|
507
|
+
for (const p of paths) {
|
|
508
|
+
try {
|
|
509
|
+
fs.watch(path.resolve(process.cwd(), p), { recursive: true }, () => {
|
|
510
|
+
console.clear();
|
|
511
|
+
console.log(`[SLOPPY WATCH] Reloaded at ${new Date().toLocaleTimeString()}`);
|
|
512
|
+
void runInspection();
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
catch { }
|
|
516
|
+
}
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
await runInspection();
|
|
520
|
+
}
|
|
521
|
+
catch (error) {
|
|
522
|
+
const message = `Check failed: ${error.message}`;
|
|
523
|
+
if (json)
|
|
524
|
+
emitJson({ version: cliVersion(), ok: false, error: message });
|
|
525
|
+
fail(message);
|
|
526
|
+
}
|
|
527
|
+
return true;
|
|
528
|
+
}
|
|
529
|
+
if (command === 'install-mcp') {
|
|
530
|
+
const client = args[args.indexOf('--client') + 1];
|
|
531
|
+
const dir = args.includes('--dir') ? path.resolve(process.cwd(), args[args.indexOf('--dir') + 1]) : process.cwd();
|
|
532
|
+
if (!['cursor', 'vscode', 'claude', 'codex'].includes(client)) {
|
|
533
|
+
fail('Usage: sloppy install-mcp --client <cursor|vscode|claude|codex> [--dir <path>] [--write]');
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
536
|
+
const snippet = '[mcp_servers.sloppy]\ncommand = "npx"\nargs = ["-y", "sloppy", "mcp"]';
|
|
537
|
+
if (client === 'codex') {
|
|
538
|
+
if (!args.includes('--write')) {
|
|
539
|
+
if (json)
|
|
540
|
+
emitJson({ client, written: false, snippet });
|
|
541
|
+
else
|
|
542
|
+
console.log(`${snippet}\nNo file written. Pass --write to append this entry to ~/.codex/config.toml.`);
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
const dest = path.join(process.env.HOME || dir, '.codex/config.toml');
|
|
546
|
+
let content = readOptionalFile(dest) || '';
|
|
547
|
+
content = content.replace(/\n?\[mcp_servers\.sloppy\][\s\S]*?(?=\n\[|$)/, '').trimEnd();
|
|
548
|
+
writeFileSafe(dest, `${content}${content ? '\n\n' : ''}${snippet}\n`, true);
|
|
549
|
+
if (json)
|
|
550
|
+
emitJson({ client, written: true, path: dest });
|
|
551
|
+
else
|
|
552
|
+
console.log(`Wrote ${dest}`);
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
const relative = { cursor: '.cursor/mcp.json', vscode: '.vscode/mcp.json', claude: '.mcp.json' }[client];
|
|
556
|
+
const dest = path.join(dir, relative);
|
|
557
|
+
let config = {};
|
|
558
|
+
try {
|
|
559
|
+
const raw = readOptionalFile(dest);
|
|
560
|
+
if (raw !== null)
|
|
561
|
+
config = JSON.parse(raw);
|
|
562
|
+
}
|
|
563
|
+
catch (error) {
|
|
564
|
+
fail(`Cannot parse ${dest}: ${error.message}`);
|
|
565
|
+
return true;
|
|
566
|
+
}
|
|
567
|
+
const key = client === 'vscode' ? 'servers' : 'mcpServers';
|
|
568
|
+
config[key] ||= {};
|
|
569
|
+
config[key].sloppy = { command: 'npx', args: ['-y', 'sloppy', 'mcp'] };
|
|
570
|
+
writeFileSafe(dest, `${JSON.stringify(config, null, 2)}\n`, true);
|
|
571
|
+
if (json)
|
|
572
|
+
emitJson({ client, written: true, path: dest });
|
|
573
|
+
else
|
|
574
|
+
console.log(`Wrote ${dest}`);
|
|
575
|
+
return true;
|
|
576
|
+
}
|
|
577
|
+
if (command === 'setup') {
|
|
578
|
+
const isGlobal = args.includes('--global') || args.includes('-g');
|
|
579
|
+
const shouldWrite = args.includes('--write') || args.includes('-w');
|
|
580
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || '';
|
|
581
|
+
const mcpResults = [];
|
|
582
|
+
const skillResults = [];
|
|
583
|
+
const inProject = process.cwd() !== '/' && process.cwd() !== homeDir && (fs.existsSync(path.join(process.cwd(), 'package.json')) || fs.existsSync(path.join(process.cwd(), '.git')));
|
|
584
|
+
const useGlobal = isGlobal || !inProject;
|
|
585
|
+
const mcpClients = [
|
|
586
|
+
{ id: 'cursor', file: useGlobal ? path.join(homeDir, '.cursor/mcp.json') : path.join(process.cwd(), '.cursor/mcp.json'), key: 'mcpServers' },
|
|
587
|
+
{ id: 'vscode', file: useGlobal ? path.join(homeDir, 'Library/Application Support/Code/User/globalStorage/mcp.json') : path.join(process.cwd(), '.vscode/mcp.json'), key: 'servers' },
|
|
588
|
+
{ id: 'claude', file: useGlobal ? path.join(homeDir, '.claude.json') : path.join(process.cwd(), '.mcp.json'), key: 'mcpServers' }
|
|
589
|
+
];
|
|
590
|
+
for (const client of mcpClients) {
|
|
591
|
+
try {
|
|
592
|
+
if (shouldWrite) {
|
|
593
|
+
let config = {};
|
|
594
|
+
const raw = readOptionalFile(client.file);
|
|
595
|
+
if (raw !== null) {
|
|
596
|
+
try {
|
|
597
|
+
config = JSON.parse(raw);
|
|
598
|
+
}
|
|
599
|
+
catch { }
|
|
600
|
+
}
|
|
601
|
+
config[client.key] = config[client.key] || {};
|
|
602
|
+
config[client.key].sloppy = { command: 'npx', args: ['-y', 'sloppy', 'mcp'] };
|
|
603
|
+
writeFileSafe(client.file, `${JSON.stringify(config, null, 2)}\n`, true);
|
|
604
|
+
mcpResults.push({ client: client.id, path: client.file, status: 'configured' });
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
mcpResults.push({ client: client.id, path: client.file, status: 'dry-run (pass --write to save)' });
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
catch (err) {
|
|
611
|
+
mcpResults.push({ client: client.id, path: client.file, status: `error: ${err.message}` });
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
const codexFile = path.join(homeDir, '.codex/config.toml');
|
|
615
|
+
const codexSnippet = '[mcp_servers.sloppy]\ncommand = "npx"\nargs = ["-y", "sloppy", "mcp"]';
|
|
616
|
+
if (shouldWrite) {
|
|
617
|
+
try {
|
|
618
|
+
let content = readOptionalFile(codexFile) || '';
|
|
619
|
+
content = content.replace(/\n?\[mcp_servers\.sloppy\][\s\S]*?(?=\n\[|$)/, '').trimEnd();
|
|
620
|
+
writeFileSafe(codexFile, `${content}${content ? '\n\n' : ''}${codexSnippet}\n`, true);
|
|
621
|
+
mcpResults.push({ client: 'codex', path: codexFile, status: 'configured' });
|
|
622
|
+
}
|
|
623
|
+
catch (err) {
|
|
624
|
+
mcpResults.push({ client: 'codex', path: codexFile, status: `error: ${err.message}` });
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
mcpResults.push({ client: 'codex', path: codexFile, status: 'dry-run (pass --write to save)' });
|
|
629
|
+
}
|
|
630
|
+
const sourceSkillDir = path.resolve(ROOT_DIR, 'skills/sloppy');
|
|
631
|
+
const skillTargets = [
|
|
632
|
+
{ name: 'Universal Agents', dir: path.join(homeDir, '.agents/skills/sloppy') },
|
|
633
|
+
{ name: 'Antigravity', dir: path.join(homeDir, '.gemini/config/skills/sloppy') },
|
|
634
|
+
{ name: 'Claude Code', dir: path.join(homeDir, '.claude/skills/sloppy') }
|
|
635
|
+
];
|
|
636
|
+
if (fs.existsSync(sourceSkillDir)) {
|
|
637
|
+
for (const target of skillTargets) {
|
|
638
|
+
if (shouldWrite) {
|
|
639
|
+
try {
|
|
640
|
+
fs.mkdirSync(path.dirname(target.dir), { recursive: true });
|
|
641
|
+
try {
|
|
642
|
+
fs.symlinkSync(sourceSkillDir, target.dir, 'dir');
|
|
643
|
+
skillResults.push({ target: target.name, path: target.dir, status: 'symlinked' });
|
|
644
|
+
}
|
|
645
|
+
catch (err) {
|
|
646
|
+
if (err?.code === 'EEXIST') {
|
|
647
|
+
skillResults.push({ target: target.name, path: target.dir, status: 'already-installed' });
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
fs.cpSync(sourceSkillDir, target.dir, { recursive: true });
|
|
651
|
+
skillResults.push({ target: target.name, path: target.dir, status: 'copied' });
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
catch (err) {
|
|
656
|
+
skillResults.push({ target: target.name, path: target.dir, status: `error: ${err.message}` });
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
skillResults.push({ target: target.name, path: target.dir, status: 'dry-run (pass --write to save)' });
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
const pluginDoorResults = [];
|
|
665
|
+
const pluginDoors = [
|
|
666
|
+
{ platform: 'Claude Code', path: path.join(process.cwd(), '.claude-plugin/plugin.json'), content: { name: 'sloppy', version: '1.4.0', description: 'Zero-tolerance AI slop UI fixer and craft certification engine', skills: ['skills/sloppy', 'skills/sloppy-ui', 'skills/sloppy-copywriting', 'skills/sloppy-human', 'skills/sloppy-layoutmobile', 'skills/sloppy-code'], entrypoint: 'skills/sloppy/SKILL.md' } },
|
|
667
|
+
{ platform: 'Cursor', path: path.join(process.cwd(), '.cursor-plugin/plugin.json'), content: { name: 'sloppy', version: '1.4.0', description: 'Zero-tolerance AI slop UI fixer for Cursor', rules: ['skills/sloppy/SKILL.md', 'skills/sloppy-ui/SKILL.md', 'skills/sloppy-copywriting/SKILL.md', 'skills/sloppy-human/SKILL.md', 'skills/sloppy-layoutmobile/SKILL.md', 'skills/sloppy-code/SKILL.md'] } },
|
|
668
|
+
{ platform: 'OpenAI Codex', path: path.join(process.cwd(), '.codex-plugin/plugin.json'), content: { name: 'sloppy', version: '1.4.0', description: 'Zero-tolerance AI slop UI fixer for OpenAI Codex', skills: ['skills/sloppy'] } },
|
|
669
|
+
{ platform: 'Cline', path: path.join(process.cwd(), '.cline-plugin/plugin.json'), content: { name: 'sloppy', version: '1.4.0', description: 'Zero-tolerance AI slop UI fixer for Cline', skills: ['skills/sloppy'] } }
|
|
670
|
+
];
|
|
671
|
+
for (const door of pluginDoors) {
|
|
672
|
+
if (shouldWrite) {
|
|
673
|
+
try {
|
|
674
|
+
const outcome = writeFileSafe(door.path, `${JSON.stringify(door.content, null, 2)}\n`, false);
|
|
675
|
+
pluginDoorResults.push({ platform: door.platform, path: door.path, status: outcome === 'exists' ? 'active' : 'configured' });
|
|
676
|
+
}
|
|
677
|
+
catch (err) {
|
|
678
|
+
pluginDoorResults.push({ platform: door.platform, path: door.path, status: `error: ${err.message}` });
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
pluginDoorResults.push({ platform: door.platform, path: door.path, status: fs.existsSync(door.path) ? 'active' : 'dry-run (pass --write to save)' });
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
const stack = detectProjectStack(process.cwd());
|
|
686
|
+
const configPath = path.resolve(process.cwd(), 'sloppy.config.json');
|
|
687
|
+
let configStatus = 'already-exists';
|
|
688
|
+
if (shouldWrite) {
|
|
689
|
+
try {
|
|
690
|
+
const outcome = writeFileSafe(configPath, JSON.stringify(stack.suggestedConfig, null, 2) + '\n', false);
|
|
691
|
+
configStatus = outcome === 'exists' ? 'already-exists' : 'generated';
|
|
692
|
+
}
|
|
693
|
+
catch (err) {
|
|
694
|
+
configStatus = `error: ${err.message}`;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
else if (!fs.existsSync(configPath)) {
|
|
698
|
+
configStatus = 'dry-run (pass --write to generate)';
|
|
699
|
+
}
|
|
700
|
+
const summary = {
|
|
701
|
+
ok: true,
|
|
702
|
+
mode: shouldWrite ? 'applied' : 'dry-run',
|
|
703
|
+
cli: { command: 'sloppy', status: 'available' },
|
|
704
|
+
stack: stack.summary,
|
|
705
|
+
config: { path: configPath, status: configStatus },
|
|
706
|
+
mcp: mcpResults,
|
|
707
|
+
skills: skillResults,
|
|
708
|
+
plugins: pluginDoorResults,
|
|
709
|
+
instructions: shouldWrite ? 'Setup complete. Restart your editor or agent session to load Sloppy.' : 'Run with --write to apply configurations.'
|
|
710
|
+
};
|
|
711
|
+
if (json) {
|
|
712
|
+
emitJson(summary);
|
|
713
|
+
}
|
|
714
|
+
else {
|
|
715
|
+
console.log('\n======================================================');
|
|
716
|
+
console.log('SLOPPY: ALL-IN-ONE SYSTEM SETUP');
|
|
717
|
+
console.log(`Mode: ${shouldWrite ? 'APPLIED (--write)' : 'DRY-RUN (pass --write to save)'}`);
|
|
718
|
+
console.log('======================================================\n');
|
|
719
|
+
console.log('1. Model Context Protocol (MCP) Clients:');
|
|
720
|
+
for (const m of mcpResults)
|
|
721
|
+
console.log(` - [${m.client.toUpperCase()}] ${m.status}: ${m.path}`);
|
|
722
|
+
console.log('\n2. Agent Skills:');
|
|
723
|
+
for (const s of skillResults)
|
|
724
|
+
console.log(` - [${s.target}] ${s.status}: ${s.path}`);
|
|
725
|
+
console.log('\n3. Native Plugin Doors:');
|
|
726
|
+
for (const p of pluginDoorResults)
|
|
727
|
+
console.log(` - [${p.platform.toUpperCase()}] ${p.status}: ${p.path}`);
|
|
728
|
+
console.log('\n4. Project Stack & Configuration:');
|
|
729
|
+
for (const item of stack.summary)
|
|
730
|
+
console.log(` - ${item}`);
|
|
731
|
+
console.log(` - Configuration: [${configStatus.toUpperCase()}] ${configPath}`);
|
|
732
|
+
console.log(`\n${summary.instructions}\n`);
|
|
733
|
+
}
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
738
|
+
export async function runCli(args) {
|
|
739
|
+
const command = args.find(arg => !['--json', '--quiet'].includes(arg)) || 'help';
|
|
740
|
+
const commandIndex = args.indexOf(command);
|
|
741
|
+
const commandArgs = args.filter((_, index) => index !== commandIndex);
|
|
742
|
+
const json = args.includes('--json');
|
|
743
|
+
if (await handleAgentCommand(command, commandArgs))
|
|
744
|
+
return;
|
|
745
|
+
switch (command) {
|
|
746
|
+
case 'audit': {
|
|
747
|
+
const valueFlags = new Set(['--type', '--tier', '--mode']);
|
|
748
|
+
const isChanged = args.includes('--changed');
|
|
749
|
+
const isStaged = args.includes('--staged');
|
|
750
|
+
const auditTargets = [];
|
|
751
|
+
for (let i = 0; i < commandArgs.length; i++) {
|
|
752
|
+
if (valueFlags.has(commandArgs[i])) {
|
|
753
|
+
i++;
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
if (commandArgs[i].startsWith('-'))
|
|
757
|
+
continue;
|
|
758
|
+
auditTargets.push(commandArgs[i]);
|
|
759
|
+
}
|
|
760
|
+
if (!auditTargets.length && !isChanged && !isStaged) {
|
|
761
|
+
console.error('[ERROR] Please specify a file or directory to audit: sloppy audit <path...> [--changed|--staged]');
|
|
762
|
+
process.exit(2);
|
|
763
|
+
}
|
|
764
|
+
for (const target of auditTargets) {
|
|
765
|
+
const resolved = path.resolve(process.cwd(), target);
|
|
766
|
+
try {
|
|
767
|
+
fs.statSync(resolved);
|
|
768
|
+
}
|
|
769
|
+
catch {
|
|
770
|
+
console.error(`[ERROR] Target not found: ${resolved}`);
|
|
771
|
+
process.exit(2);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
const filesToAudit = isStaged
|
|
775
|
+
? collectGitChangedFiles('staged', auditTargets)
|
|
776
|
+
: isChanged
|
|
777
|
+
? collectGitChangedFiles('changed', auditTargets)
|
|
778
|
+
: collectFiles(auditTargets);
|
|
779
|
+
const resolveContext = createDirContextResolver();
|
|
780
|
+
const isFloorOnly = args.includes('--floor-only');
|
|
781
|
+
const isStrict = args.includes('--strict');
|
|
782
|
+
const isCodeOnly = args.includes('--code') || args.includes('--code-only');
|
|
783
|
+
const isCompact = args.includes('--compact');
|
|
784
|
+
const isAfterMode = (args.includes('--mode') && args[args.indexOf('--mode') + 1] === 'after') || args.includes('--report') || args.includes('--after');
|
|
785
|
+
const tierIndex = args.indexOf('--tier');
|
|
786
|
+
const targetTier = tierIndex !== -1 && args[tierIndex + 1] ? args[tierIndex + 1] : undefined;
|
|
787
|
+
if (!json) {
|
|
788
|
+
console.log(`\n======================================================`);
|
|
789
|
+
console.log(`SLOPPY: AI SLOP AUDIT REPORT ${isAfterMode ? '[AFTER-MODE APPROVAL GATE]' : isCodeOnly ? '[LOW-EVIDENCE TS/REACT CODE]' : isFloorOnly ? '[FLOOR-ONLY SCAN]' : '[3-TIER GATE]'}`);
|
|
790
|
+
console.log(`Auditing ${filesToAudit.length} file(s)...`);
|
|
791
|
+
console.log(`======================================================\n`);
|
|
792
|
+
}
|
|
793
|
+
const auditedFiles = [];
|
|
794
|
+
let totalViolations = 0;
|
|
795
|
+
let totalFloorIssues = 0;
|
|
796
|
+
let totalReflexIssues = 0;
|
|
797
|
+
let totalOverruled = 0;
|
|
798
|
+
let totalFinishIssues = 0;
|
|
799
|
+
let maxScore = 0;
|
|
800
|
+
let anyFloorFailed = false;
|
|
801
|
+
let anyReflexFailed = false;
|
|
802
|
+
for (const file of filesToAudit) {
|
|
803
|
+
const content = fs.readFileSync(file, 'utf8');
|
|
804
|
+
const relPath = path.relative(process.cwd(), file);
|
|
805
|
+
const ctx = resolveContext(file);
|
|
806
|
+
const result = auditCode(content, {
|
|
807
|
+
filepath: relPath,
|
|
808
|
+
componentType: surfaceType(args),
|
|
809
|
+
floorOnly: isFloorOnly,
|
|
810
|
+
tier: targetTier,
|
|
811
|
+
mode: isAfterMode ? 'after' : 'during',
|
|
812
|
+
report: isAfterMode,
|
|
813
|
+
codeOnly: isCodeOnly,
|
|
814
|
+
strict: isStrict,
|
|
815
|
+
config: ctx.config ?? undefined,
|
|
816
|
+
designContract: ctx.designContract
|
|
817
|
+
});
|
|
818
|
+
totalViolations += result.violations.length;
|
|
819
|
+
totalFloorIssues += result.stats.floorCount;
|
|
820
|
+
totalReflexIssues += result.stats.reflexCount;
|
|
821
|
+
totalOverruled += result.stats.overruledCount;
|
|
822
|
+
totalFinishIssues += result.stats.finishCount;
|
|
823
|
+
maxScore = Math.max(maxScore, result.slopScore);
|
|
824
|
+
if (!result.passedFloor)
|
|
825
|
+
anyFloorFailed = true;
|
|
826
|
+
if (!result.passedReflex)
|
|
827
|
+
anyReflexFailed = true;
|
|
828
|
+
auditedFiles.push({ path: relPath, score: result.slopScore, isSlopFree: result.isSlopFree, passedFloor: result.passedFloor, passedReflex: result.passedReflex, violations: result.violations, stats: result.stats, summary: result.summary, reportPath: result.reportPath });
|
|
829
|
+
if (json)
|
|
830
|
+
continue;
|
|
831
|
+
if (result.violations.length > 0) {
|
|
832
|
+
const statusBadge = !result.passedFloor ? '[FLOOR BLOCKED]' : result.slopScore >= 50 ? '[SEVERE SLOP]' : '[MODERATE SLOP]';
|
|
833
|
+
console.log(`--- ${relPath} ${statusBadge} (Score: ${result.slopScore}/100) ---`);
|
|
834
|
+
for (const v of result.violations) {
|
|
835
|
+
const loc = v.line ? `Line ${v.line}: ` : '';
|
|
836
|
+
const idxBadge = v.index ? `[#${v.index}] ` : '';
|
|
837
|
+
const tierBadge = v.tier ? `[${v.tier.toUpperCase()}]` : '';
|
|
838
|
+
const overruleNote = v.overruled ? ` (OVERRULED: "${v.overruleRationale}")` : '';
|
|
839
|
+
console.log(` ${idxBadge}${tierBadge} [${v.severity.toUpperCase()}] ${v.type}${overruleNote}`);
|
|
840
|
+
console.log(` ${loc}${v.message}`);
|
|
841
|
+
const selector = v.evidence?.selector ? ` at ${v.evidence.selector}` : '';
|
|
842
|
+
const criterion = v.evidence?.criterion ? ` (${v.evidence.criterion})` : '';
|
|
843
|
+
console.log(` Evidence: ${v.confidence}/${v.evidence?.kind || 'source'}${selector}${criterion} - ${v.objective ? 'objective defect' : 'craft judgment'}`);
|
|
844
|
+
if (v.snippet) {
|
|
845
|
+
console.log(` Code: "${v.snippet.slice(0, 80)}"`);
|
|
846
|
+
}
|
|
847
|
+
console.log(` Fix: ${v.recommendation}\n`);
|
|
848
|
+
}
|
|
849
|
+
if (result.reportPath) {
|
|
850
|
+
console.log(`[SLOPPY AFTER-AUDIT] Numbered audit report generated: ${result.reportPath}`);
|
|
851
|
+
console.log(`Approval required before modifying code.`);
|
|
852
|
+
console.log(`To apply approved fixes surgically, run:`);
|
|
853
|
+
console.log(` sloppy fix ${relPath} --only <numbers> --write\n`);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
else {
|
|
857
|
+
console.log(`[PASS] ${relPath} - Zero AI slop detected (Score: 0/100)`);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
const gateOk = !anyFloorFailed && !(isStrict && anyReflexFailed) && (isFloorOnly || maxScore <= 40);
|
|
861
|
+
if (json && isCompact) {
|
|
862
|
+
emitJson({
|
|
863
|
+
ok: gateOk,
|
|
864
|
+
score: maxScore,
|
|
865
|
+
totals: { files: filesToAudit.length, violations: totalViolations, floor: totalFloorIssues, reflex: totalReflexIssues, overruled: totalOverruled, finish: totalFinishIssues },
|
|
866
|
+
files: auditedFiles.filter(f => f.violations.length > 0).map(f => ({
|
|
867
|
+
path: f.path,
|
|
868
|
+
score: f.score,
|
|
869
|
+
issues: f.violations.map(v => `${v.tier}:${v.ruleId || v.type}@L${v.line}`)
|
|
870
|
+
}))
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
else if (json) {
|
|
874
|
+
emitJson({
|
|
875
|
+
version: cliVersion(),
|
|
876
|
+
ok: gateOk,
|
|
877
|
+
score: maxScore,
|
|
878
|
+
totals: { files: filesToAudit.length, violations: totalViolations, floor: totalFloorIssues, reflex: totalReflexIssues, overruled: totalOverruled, finish: totalFinishIssues },
|
|
879
|
+
files: auditedFiles,
|
|
880
|
+
nextActions: auditedFiles.filter((f) => f.violations.length > 0).map((f) => `Run: sloppy fix ${f.path} --diff`)
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
else {
|
|
884
|
+
console.log(`------------------------------------------------------`);
|
|
885
|
+
console.log(`3-Tier Severity Gate Summary:`);
|
|
886
|
+
console.log(` Files scanned: ${filesToAudit.length}`);
|
|
887
|
+
console.log(` Floor Gates: ${totalFloorIssues} blockers ${anyFloorFailed ? '[FAILED - CI BLOCKER]' : '[PASSED]'}`);
|
|
888
|
+
console.log(` Reflex Gates: ${totalReflexIssues} AI defaults (${totalOverruled} justified with written rationale) ${anyReflexFailed ? '[ACTION REQUIRED]' : '[PASSED]'}`);
|
|
889
|
+
console.log(` Finish Polish: ${totalFinishIssues} advisory suggestions`);
|
|
890
|
+
console.log(` Peak slop score: ${maxScore}/100`);
|
|
891
|
+
console.log(`------------------------------------------------------\n`);
|
|
892
|
+
}
|
|
893
|
+
if (anyFloorFailed) {
|
|
894
|
+
console.error(`[CI GATE BLOCKED] Critical accessibility, contrast, or broken layout Floor gates failed.`);
|
|
895
|
+
process.exitCode = 1;
|
|
896
|
+
}
|
|
897
|
+
else if (isStrict && anyReflexFailed) {
|
|
898
|
+
console.error(`[STRICT MODE FAILED] Unjustified AI Reflex patterns detected without written rationale in sloppy.config.json or inline comments.`);
|
|
899
|
+
process.exitCode = 1;
|
|
900
|
+
}
|
|
901
|
+
else if (maxScore > 40 && !isFloorOnly) {
|
|
902
|
+
process.exitCode = 1;
|
|
903
|
+
}
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
case 'fix': {
|
|
907
|
+
const usingStdin = args.includes('--stdin');
|
|
908
|
+
const shouldWrite = args.includes('--write') || args.includes('-w');
|
|
909
|
+
const shouldDiff = args.includes('--diff');
|
|
910
|
+
const shouldCheck = args.includes('--check');
|
|
911
|
+
const checkWiring = !args.includes('--no-kept');
|
|
912
|
+
const lookIdx = args.indexOf('--look');
|
|
913
|
+
const look = lookIdx !== -1 && args[lookIdx + 1] ? args[lookIdx + 1] : 'linear';
|
|
914
|
+
const onlyIdx = args.indexOf('--only');
|
|
915
|
+
const onlyParam = onlyIdx !== -1 && args[onlyIdx + 1] ? args[onlyIdx + 1].split(',').map(s => s.trim()) : undefined;
|
|
916
|
+
let originalCode = '';
|
|
917
|
+
let targetPath;
|
|
918
|
+
let label = 'stdin';
|
|
919
|
+
if (usingStdin) {
|
|
920
|
+
const chunks = [];
|
|
921
|
+
for await (const chunk of process.stdin)
|
|
922
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
923
|
+
originalCode = Buffer.concat(chunks).toString('utf8');
|
|
924
|
+
}
|
|
925
|
+
else {
|
|
926
|
+
const target = args[1];
|
|
927
|
+
if (!target || target.startsWith('-')) {
|
|
928
|
+
const message = 'Usage: sloppy fix <file> [--diff|--check|--write] [--look <look>] [--only <ids>] [--json] | sloppy fix --stdin';
|
|
929
|
+
if (json)
|
|
930
|
+
emitJson({ ok: false, error: message });
|
|
931
|
+
else
|
|
932
|
+
console.error(`[ERROR] ${message}`);
|
|
933
|
+
process.exitCode = 2;
|
|
934
|
+
break;
|
|
935
|
+
}
|
|
936
|
+
targetPath = path.resolve(process.cwd(), target);
|
|
937
|
+
if (!fs.existsSync(targetPath)) {
|
|
938
|
+
const message = `File not found: ${target}`;
|
|
939
|
+
if (json)
|
|
940
|
+
emitJson({ ok: false, error: message });
|
|
941
|
+
else
|
|
942
|
+
console.error(`[ERROR] ${message}`);
|
|
943
|
+
process.exitCode = 2;
|
|
944
|
+
break;
|
|
945
|
+
}
|
|
946
|
+
originalCode = fs.readFileSync(targetPath, 'utf-8');
|
|
947
|
+
label = path.relative(process.cwd(), targetPath);
|
|
948
|
+
}
|
|
949
|
+
const result = transformSlopToCraft(originalCode, { look, kept: checkWiring, filepath: label, only: onlyParam });
|
|
950
|
+
const changed = result.transformedCode !== originalCode;
|
|
951
|
+
const wiring = result.wiringGuard;
|
|
952
|
+
const writeBlocked = shouldWrite && Boolean((wiring && !wiring.passed) || !result.isValidSyntax);
|
|
953
|
+
if (shouldWrite && !writeBlocked && targetPath)
|
|
954
|
+
fs.writeFileSync(targetPath, result.transformedCode, 'utf8');
|
|
955
|
+
if (json) {
|
|
956
|
+
emitJson({
|
|
957
|
+
ok: result.isValidSyntax && (!wiring || wiring.passed) && !(shouldCheck && changed),
|
|
958
|
+
changed,
|
|
959
|
+
changesApplied: result.changesApplied,
|
|
960
|
+
isValidSyntax: result.isValidSyntax,
|
|
961
|
+
syntaxErrors: result.syntaxErrors,
|
|
962
|
+
transformedCode: result.transformedCode,
|
|
963
|
+
unifiedDiff: result.unifiedDiff,
|
|
964
|
+
only: onlyParam ?? null,
|
|
965
|
+
transformations: result.transformations,
|
|
966
|
+
preAudit: result.preAudit,
|
|
967
|
+
postAudit: result.postAudit,
|
|
968
|
+
wiringGuard: wiring ?? null,
|
|
969
|
+
manualReviewItems: result.manualReviewItems
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
else {
|
|
973
|
+
// The wiring block is printed on every fix path. When stdout carries code
|
|
974
|
+
// or a diff, the block goes to stderr so the output stays machine-clean.
|
|
975
|
+
const stream = (usingStdin || shouldDiff) ? console.error : console.log;
|
|
976
|
+
stream(`Wiring Guard ${wiring ? (wiring.passed ? '[PASSED]' : '[DROPPED WIRING DETECTED]') : '[SKIPPED]'}: ${wiring ? wiring.details : 'disabled with --no-kept'}`);
|
|
977
|
+
if (wiring && !wiring.passed)
|
|
978
|
+
wiring.dropped.forEach(d => stream(` - ${d.reason}`));
|
|
979
|
+
result.manualReviewItems.forEach(item => stream(` review: ${item}`));
|
|
980
|
+
if (shouldDiff)
|
|
981
|
+
process.stdout.write(result.unifiedDiff);
|
|
982
|
+
else if (usingStdin)
|
|
983
|
+
process.stdout.write(result.transformedCode);
|
|
984
|
+
else {
|
|
985
|
+
console.log(`\n======================================================`);
|
|
986
|
+
console.log(`SLOPPY: SURGICAL AI SLOP AUTO-FIXER`);
|
|
987
|
+
console.log(`Target: ${label}`);
|
|
988
|
+
if (onlyParam)
|
|
989
|
+
console.log(`Surgical Filter: Only applying fixes for [${onlyParam.join(', ')}]`);
|
|
990
|
+
console.log(`======================================================\n`);
|
|
991
|
+
console.log(`Slop Score: ${result.preAudit.slopScore}/100 -> ${result.postAudit.slopScore}/100`);
|
|
992
|
+
console.log(`Changes Applied: ${result.changesApplied}\n`);
|
|
993
|
+
result.transformations.forEach((t, i) => {
|
|
994
|
+
console.log(`${i + 1}. [${t.type}] ${t.explanation}`);
|
|
995
|
+
console.log(` Before: "${t.original.slice(0, 60)}"`);
|
|
996
|
+
console.log(` After: "${t.replacement.slice(0, 60)}"\n`);
|
|
997
|
+
});
|
|
998
|
+
console.log(writeBlocked ? '[INFO] Nothing written.' : shouldWrite ? `[SUCCESS] Wrote ${label}` : '[INFO] Dry-run complete. Run with "--write" (or "-w") to save changes.');
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
if (writeBlocked) {
|
|
1002
|
+
const message = wiring && !wiring.passed
|
|
1003
|
+
? 'Refusing to write: the wiring guard detected dropped handlers or links.'
|
|
1004
|
+
: `Refusing to write invalid syntax: ${result.syntaxErrors.map(error => error.message).join('; ')}`;
|
|
1005
|
+
if (!json)
|
|
1006
|
+
console.error(`[ERROR] ${message}`);
|
|
1007
|
+
process.exitCode = 1;
|
|
1008
|
+
}
|
|
1009
|
+
else if (shouldCheck && changed) {
|
|
1010
|
+
process.exitCode = 1;
|
|
1011
|
+
}
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
case 'plan': {
|
|
1015
|
+
const target = args[1];
|
|
1016
|
+
if (!target) {
|
|
1017
|
+
console.error('[ERROR] Please specify a file to plan repairs for: sloppy plan <path> [--look <look>]');
|
|
1018
|
+
process.exit(2);
|
|
1019
|
+
}
|
|
1020
|
+
const targetPath = path.resolve(process.cwd(), target);
|
|
1021
|
+
if (!fs.existsSync(targetPath)) {
|
|
1022
|
+
console.error(`[ERROR] File not found: ${targetPath}`);
|
|
1023
|
+
process.exit(2);
|
|
1024
|
+
}
|
|
1025
|
+
const lookIdx = args.indexOf('--look');
|
|
1026
|
+
const look = lookIdx !== -1 && args[lookIdx + 1] ? args[lookIdx + 1] : 'linear';
|
|
1027
|
+
const code = fs.readFileSync(targetPath, 'utf-8');
|
|
1028
|
+
const plan = createRepairPlan(code, { filepath: targetPath, look });
|
|
1029
|
+
if (json) {
|
|
1030
|
+
emitJson({ version: cliVersion(), ok: plan.isValidSyntax, filepath: targetPath, ...plan });
|
|
1031
|
+
break;
|
|
1032
|
+
}
|
|
1033
|
+
console.log(`\n======================================================`);
|
|
1034
|
+
console.log(`SLOPPY STRUCTURED REPAIR PLAN`);
|
|
1035
|
+
console.log(`Target: ${path.relative(process.cwd(), targetPath)}`);
|
|
1036
|
+
console.log(`======================================================\n`);
|
|
1037
|
+
console.log(`Initial Slop Score: ${plan.initialScore}/100`);
|
|
1038
|
+
console.log(`Projected Post-Repair: ${plan.projectedScore}/100`);
|
|
1039
|
+
console.log(`Score Improvement: +${plan.scoreImprovement} points`);
|
|
1040
|
+
console.log(`Safe Auto-Patches: ${plan.safePatchesCount}`);
|
|
1041
|
+
console.log(`Manual Review Items: ${plan.manualReviewCount}`);
|
|
1042
|
+
console.log(`Syntax Validity: ${plan.isValidSyntax ? 'VALID' : 'CHECK TAGS'}\n`);
|
|
1043
|
+
console.log(`--- Planned Patches ---`);
|
|
1044
|
+
plan.patches.forEach((p, idx) => {
|
|
1045
|
+
const flag = p.autoApplicable ? '[AUTO-APPLY]' : '[MANUAL-REVIEW]';
|
|
1046
|
+
console.log(`${idx + 1}. ${flag} ${p.ruleId} (Confidence: ${p.confidence.toUpperCase()}, Risk: ${p.risk.toUpperCase()})`);
|
|
1047
|
+
console.log(` Rationale: ${p.rationale}`);
|
|
1048
|
+
if (p.originalSnippet) {
|
|
1049
|
+
console.log(` Original: "${p.originalSnippet.slice(0, 70)}"`);
|
|
1050
|
+
}
|
|
1051
|
+
console.log(` Proposed: "${p.replacementSnippet.slice(0, 70)}"\n`);
|
|
1052
|
+
});
|
|
1053
|
+
console.log(`To execute auto-applicable patches, run: sloppy fix ${args[1]} --write`);
|
|
1054
|
+
break;
|
|
1055
|
+
}
|
|
1056
|
+
case 'rubric': {
|
|
1057
|
+
const target = args[1];
|
|
1058
|
+
if (!target) {
|
|
1059
|
+
console.error('[ERROR] Please specify a file to evaluate: sloppy rubric <path> [--strict]');
|
|
1060
|
+
process.exit(2);
|
|
1061
|
+
}
|
|
1062
|
+
const targetPath = path.resolve(process.cwd(), target);
|
|
1063
|
+
if (!fs.existsSync(targetPath)) {
|
|
1064
|
+
console.error(`[ERROR] File not found: ${targetPath}`);
|
|
1065
|
+
process.exit(2);
|
|
1066
|
+
}
|
|
1067
|
+
const strict = args.includes('--strict');
|
|
1068
|
+
const code = fs.readFileSync(targetPath, 'utf-8');
|
|
1069
|
+
const cert = evaluateCraftRubric(code, { filepath: targetPath, strict, componentType: surfaceType(args) });
|
|
1070
|
+
if (json) {
|
|
1071
|
+
emitJson({ version: cliVersion(), ok: cert.isCertified, filepath: targetPath, ...cert });
|
|
1072
|
+
break;
|
|
1073
|
+
}
|
|
1074
|
+
console.log(`\n======================================================`);
|
|
1075
|
+
console.log(`SLOPPY CRAFT CERTIFICATION REPORT`);
|
|
1076
|
+
console.log(`Target: ${path.relative(process.cwd(), targetPath)}`);
|
|
1077
|
+
console.log(`Grade: ${cert.grade} (${cert.totalScore}/100) - ${cert.isCertified ? 'CERTIFIED' : 'FAILED'}`);
|
|
1078
|
+
console.log(`======================================================\n`);
|
|
1079
|
+
console.log(`10-Point Dimension Breakdown:`);
|
|
1080
|
+
cert.dimensions.forEach((d) => {
|
|
1081
|
+
const statusTag = d.score >= 9 ? '[EXCELLENT]' : d.score >= 7 ? '[GOOD]' : d.score >= 4 ? '[NEEDS-ATTENTION]' : '[SLOP-DETECTED]';
|
|
1082
|
+
console.log(` * ${d.name.padEnd(38)} [${d.score}/10] ${statusTag}`);
|
|
1083
|
+
console.log(` ${d.feedback}`);
|
|
1084
|
+
});
|
|
1085
|
+
console.log(`\nVerdict:`);
|
|
1086
|
+
console.log(` ${cert.verdict}\n`);
|
|
1087
|
+
console.log(`Markdown Badge:`);
|
|
1088
|
+
console.log(` ${cert.markdownBadge}\n`);
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
case 'verify': {
|
|
1092
|
+
const target = args[1] && !args[1].startsWith('-') ? args[1] : 'http://127.0.0.1:1355';
|
|
1093
|
+
const isMultiWidth = args.includes('--multi-width') || args.includes('--render') || args.includes('-m');
|
|
1094
|
+
const staticOnly = args.includes('--static');
|
|
1095
|
+
try {
|
|
1096
|
+
if (args.includes('--a11y')) {
|
|
1097
|
+
const module = await import('@sloppy-ai/verify/accessibility').catch(async () => import(path.resolve(ROOT_DIR, 'packages/verify/accessibility.mjs')));
|
|
1098
|
+
const res = await module.runAccessibilityAudit(target, { timeoutMs: 15000 });
|
|
1099
|
+
if (json)
|
|
1100
|
+
emitJson(res);
|
|
1101
|
+
else {
|
|
1102
|
+
console.log(`\n======================================================`);
|
|
1103
|
+
console.log(`SLOPPY RENDERED ACCESSIBILITY VERIFICATION`);
|
|
1104
|
+
console.log(`======================================================\n`);
|
|
1105
|
+
console.log(`Target: ${res.target} (${res.mode})`);
|
|
1106
|
+
console.log(`Summary: ${res.summary}`);
|
|
1107
|
+
for (const finding of res.findings)
|
|
1108
|
+
console.log(` [${finding.severity.toUpperCase()}] ${finding.rule}: ${finding.message}${finding.evidence?.criterion ? ` (${finding.evidence.criterion})` : ''}`);
|
|
1109
|
+
if (res.unavailable)
|
|
1110
|
+
console.error(`Accessibility unavailable: ${res.unavailable}`);
|
|
1111
|
+
}
|
|
1112
|
+
if (res.unavailable)
|
|
1113
|
+
process.exitCode = 2;
|
|
1114
|
+
else if (!res.ok)
|
|
1115
|
+
process.exitCode = 1;
|
|
1116
|
+
break;
|
|
1117
|
+
}
|
|
1118
|
+
if (isMultiWidth) {
|
|
1119
|
+
const moduleName = '@sloppy-ai/verify/multi-width';
|
|
1120
|
+
const module = await import(moduleName).catch(async () => import(path.resolve(ROOT_DIR, 'packages/verify/multi-width.mjs')));
|
|
1121
|
+
const res = await module.runMultiWidthVerification(target, { staticOnly });
|
|
1122
|
+
if (json)
|
|
1123
|
+
emitJson(res);
|
|
1124
|
+
else {
|
|
1125
|
+
console.log(`\n======================================================`);
|
|
1126
|
+
console.log(`SLOPPY MULTI-WIDTH VIEWPORT VERIFICATION (${res.totalViewportsTested} WIDTHS)`);
|
|
1127
|
+
console.log(`======================================================\n`);
|
|
1128
|
+
console.log(`Target: ${res.target} ${res.isStaticFallback ? '(Static Source Simulation)' : '(Headless Browser Render)'}`);
|
|
1129
|
+
console.log(`Summary: ${res.summary}`);
|
|
1130
|
+
console.log(`Passed: ${res.viewportsPassed}/${res.totalViewportsTested} viewports`);
|
|
1131
|
+
for (const f of res.findings)
|
|
1132
|
+
console.log(` [${f.severity.toUpperCase()}] ${f.viewportName} (${f.width}px): ${f.message}`);
|
|
1133
|
+
}
|
|
1134
|
+
if (!res.allPassed)
|
|
1135
|
+
process.exitCode = 1;
|
|
1136
|
+
break;
|
|
1137
|
+
}
|
|
1138
|
+
const { verifyTarget } = await import('@sloppy-ai/verify').catch(async () => import(path.resolve(ROOT_DIR, 'packages/verify/verification.mjs')));
|
|
1139
|
+
const result = await verifyTarget(target, { timeoutMs: 15000 });
|
|
1140
|
+
if (json)
|
|
1141
|
+
emitJson(result);
|
|
1142
|
+
else {
|
|
1143
|
+
console.log(`\n======================================================`);
|
|
1144
|
+
console.log(`SLOPPY BROWSER & GEOMETRIC VERIFICATION HARNESS`);
|
|
1145
|
+
console.log(`======================================================\n`);
|
|
1146
|
+
console.log(`Verification ${result.ok ? 'passed' : 'failed'}: ${result.target} (${result.mode})`);
|
|
1147
|
+
for (const violation of result.violations)
|
|
1148
|
+
console.log(`[${violation.rule}] ${violation.message}${violation.evidence ? `: ${violation.evidence}` : ''}`);
|
|
1149
|
+
if (result.unavailable)
|
|
1150
|
+
console.error(`Verification unavailable: ${result.unavailable}`);
|
|
1151
|
+
}
|
|
1152
|
+
if (result.unavailable)
|
|
1153
|
+
process.exitCode = 2;
|
|
1154
|
+
else if (!result.ok)
|
|
1155
|
+
process.exitCode = 1;
|
|
1156
|
+
}
|
|
1157
|
+
catch (error) {
|
|
1158
|
+
const unavailable = `Verification unavailable: ${error.message}`;
|
|
1159
|
+
if (json)
|
|
1160
|
+
emitJson({ ok: false, target, unavailable });
|
|
1161
|
+
else
|
|
1162
|
+
console.error(unavailable);
|
|
1163
|
+
process.exitCode = 2;
|
|
1164
|
+
}
|
|
1165
|
+
break;
|
|
1166
|
+
}
|
|
1167
|
+
case 'create': {
|
|
1168
|
+
const archetypeId = args[1];
|
|
1169
|
+
if (!archetypeId) {
|
|
1170
|
+
console.error('[ERROR] Please specify an archetype: sloppy create <archetypeId> [--dir <path>]');
|
|
1171
|
+
console.log(`Available archetypes: ${SYNTHESIZED_ARCHETYPES.map(a => a.id).join(', ')}`);
|
|
1172
|
+
process.exit(2);
|
|
1173
|
+
}
|
|
1174
|
+
const archetype = getSynthesizedArchetype(archetypeId);
|
|
1175
|
+
if (!archetype) {
|
|
1176
|
+
console.error(`[ERROR] Unknown archetype "${archetypeId}".`);
|
|
1177
|
+
console.log(`Run "sloppy archetypes" to view available multi-library master archetypes.`);
|
|
1178
|
+
process.exit(2);
|
|
1179
|
+
}
|
|
1180
|
+
const dirIdx = args.indexOf('--dir') !== -1 ? args.indexOf('--dir') : args.indexOf('--dest');
|
|
1181
|
+
const customDir = dirIdx !== -1 && args[dirIdx + 1] ? args[dirIdx + 1] : 'src/components';
|
|
1182
|
+
const destDir = path.resolve(process.cwd(), customDir);
|
|
1183
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
1184
|
+
const destFile = path.resolve(destDir, `${archetype.id}.tsx`);
|
|
1185
|
+
fs.writeFileSync(destFile, archetype.tsxCode, 'utf-8');
|
|
1186
|
+
console.log(`\n======================================================`);
|
|
1187
|
+
console.log(`[SUCCESS] Created Master Archetype: ${archetype.name}`);
|
|
1188
|
+
console.log(`Destination: ${path.relative(process.cwd(), destFile)}`);
|
|
1189
|
+
console.log(`Libraries Unified: ${archetype.librariesUsed.join(', ')}`);
|
|
1190
|
+
console.log(`======================================================\n`);
|
|
1191
|
+
console.log(`Anti-Slop Craft Measures Enforced:`);
|
|
1192
|
+
for (const m of archetype.antiSlopMeasures) {
|
|
1193
|
+
console.log(` - ${m}`);
|
|
1194
|
+
}
|
|
1195
|
+
console.log(`\nFocal Point: ${archetype.focalPoint}`);
|
|
1196
|
+
break;
|
|
1197
|
+
}
|
|
1198
|
+
case 'archetypes': {
|
|
1199
|
+
if (json) {
|
|
1200
|
+
emitJson(SYNTHESIZED_ARCHETYPES);
|
|
1201
|
+
break;
|
|
1202
|
+
}
|
|
1203
|
+
console.log(`\n======================================================`);
|
|
1204
|
+
console.log(`SLOPPY SYNTHESIZED MASTER ARCHETYPES (${SYNTHESIZED_ARCHETYPES.length})`);
|
|
1205
|
+
console.log(`Fusing the best MIT UI ecosystems without slop`);
|
|
1206
|
+
console.log(`======================================================\n`);
|
|
1207
|
+
for (const a of SYNTHESIZED_ARCHETYPES) {
|
|
1208
|
+
console.log(`* ${a.id.padEnd(28)} [${a.category.toUpperCase()}]`);
|
|
1209
|
+
console.log(` Name: ${a.name}`);
|
|
1210
|
+
console.log(` Description: ${a.description}`);
|
|
1211
|
+
console.log(` Libraries: ${a.librariesUsed.join(' + ')}`);
|
|
1212
|
+
console.log(` Focal Point: ${a.focalPoint}\n`);
|
|
1213
|
+
}
|
|
1214
|
+
console.log(`To scaffold any archetype, run: sloppy create <archetypeId>`);
|
|
1215
|
+
break;
|
|
1216
|
+
}
|
|
1217
|
+
case 'list': {
|
|
1218
|
+
if (json) {
|
|
1219
|
+
emitJson({ components: SLOPPY_COMPONENTS, patterns: PATTERNS_CATALOG, motionEcosystems: MOTION_ECOSYSTEMS });
|
|
1220
|
+
break;
|
|
1221
|
+
}
|
|
1222
|
+
const libFilter = args[1]?.toLowerCase();
|
|
1223
|
+
if (libFilter && SLOPPY_LIBRARIES[libFilter]) {
|
|
1224
|
+
console.log(`\n======================================================`);
|
|
1225
|
+
console.log(`SLOPPY COMPONENTS: ${SLOPPY_LIBRARIES[libFilter].name.toUpperCase()}`);
|
|
1226
|
+
console.log(`Author: ${SLOPPY_LIBRARIES[libFilter].author} | ${SLOPPY_LIBRARIES[libFilter].githubUrl}`);
|
|
1227
|
+
console.log(`======================================================\n`);
|
|
1228
|
+
const comps = SLOPPY_COMPONENTS.filter(c => c.library === libFilter);
|
|
1229
|
+
for (const c of comps) {
|
|
1230
|
+
console.log(`* ${c.id.padEnd(35)} [${c.category.toUpperCase()}] [${c.antiSlopRating.toUpperCase()}]`);
|
|
1231
|
+
console.log(` Name: ${c.name}`);
|
|
1232
|
+
console.log(` Description: ${c.description}`);
|
|
1233
|
+
console.log(` Guidance: ${c.antiSlopGuidance}\n`);
|
|
1234
|
+
}
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
if (libFilter === 'motion') {
|
|
1238
|
+
console.log(`\n======================================================`);
|
|
1239
|
+
console.log(`SLOPPY PERMISSIVE MOTION, 3D & LOTTIE ECOSYSTEMS (${MOTION_ECOSYSTEMS.length} MIT/Apache-2.0)`);
|
|
1240
|
+
console.log(`======================================================\n`);
|
|
1241
|
+
for (const m of MOTION_ECOSYSTEMS) {
|
|
1242
|
+
console.log(`* ${m.name} (${m.id}) [${m.category}] [${m.license}]`);
|
|
1243
|
+
console.log(` Repo: ${m.githubUrl}`);
|
|
1244
|
+
console.log(` Guidance: ${m.antiSlopGuidance}`);
|
|
1245
|
+
if (m.licenseNote)
|
|
1246
|
+
console.log(` License: ${m.licenseNote}`);
|
|
1247
|
+
console.log();
|
|
1248
|
+
}
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
console.log(`\n======================================================`);
|
|
1252
|
+
console.log(`SLOPPY UNIFIED COMPONENT & PATTERN REGISTRY`);
|
|
1253
|
+
console.log(`5 MIT Component Libraries: stageshow, shadcn, motion-primitives, magicui, kokonutui`);
|
|
1254
|
+
console.log(`Plus ${MOTION_ECOSYSTEMS.length} MIT/Apache-2.0 Motion/3D/Scroll/Lottie ecosystems (sloppy list motion)`);
|
|
1255
|
+
console.log(`======================================================\n`);
|
|
1256
|
+
console.log(`--- Highlighted Curated Components ---`);
|
|
1257
|
+
for (const c of SLOPPY_COMPONENTS) {
|
|
1258
|
+
console.log(`* ${c.id.padEnd(35)} [${c.library.toUpperCase()}] [${c.category.toUpperCase()}]`);
|
|
1259
|
+
console.log(` ${c.description}`);
|
|
1260
|
+
console.log(` Guidance: ${c.antiSlopGuidance}\n`);
|
|
1261
|
+
}
|
|
1262
|
+
console.log(`--- Flagship Product Patterns (Stageshow) ---`);
|
|
1263
|
+
for (const p of PATTERNS_CATALOG.slice(0, 8)) {
|
|
1264
|
+
const motionTag = p.hasMotion ? '[MOTION]' : '[STILL]';
|
|
1265
|
+
console.log(`* stageshow/${p.id.padEnd(25)} ${motionTag.padEnd(9)} [${p.theme.toUpperCase()}] ${p.name}`);
|
|
1266
|
+
console.log(` Focal Point: ${p.focalPoint}\n`);
|
|
1267
|
+
}
|
|
1268
|
+
console.log(`Tip: Filter by library with: sloppy list <stageshow|shadcn|motion-primitives|magicui|kokonutui|motion>`);
|
|
1269
|
+
break;
|
|
1270
|
+
}
|
|
1271
|
+
case 'libs': {
|
|
1272
|
+
console.log(`\n======================================================`);
|
|
1273
|
+
console.log(`SLOPPY INTEGRATED LIBRARIES (MIT Component Ecosystems)`);
|
|
1274
|
+
console.log(`======================================================\n`);
|
|
1275
|
+
for (const lib of Object.values(SLOPPY_LIBRARIES)) {
|
|
1276
|
+
console.log(`* ${lib.name.toUpperCase()} (id: "${lib.id}") [${lib.license}]`);
|
|
1277
|
+
console.log(` Author: ${lib.author}`);
|
|
1278
|
+
console.log(` Repository: ${lib.githubUrl}`);
|
|
1279
|
+
console.log(` Description: ${lib.description}`);
|
|
1280
|
+
console.log(` Anti-Slop Role: ${lib.antiSlopRole}`);
|
|
1281
|
+
console.log(` Core Strengths:`);
|
|
1282
|
+
for (const s of lib.strengths) {
|
|
1283
|
+
console.log(` - ${s}`);
|
|
1284
|
+
}
|
|
1285
|
+
console.log();
|
|
1286
|
+
}
|
|
1287
|
+
console.log(`======================================================`);
|
|
1288
|
+
console.log(`SUPPORTED PERMISSIVE MOTION / SCROLL / 3D / LOTTIE ECOSYSTEMS (${MOTION_ECOSYSTEMS.length})`);
|
|
1289
|
+
console.log(`======================================================\n`);
|
|
1290
|
+
for (const m of MOTION_ECOSYSTEMS) {
|
|
1291
|
+
console.log(`* ${m.name} (${m.id}) [${m.category}] [${m.license}] -> ${m.githubUrl}`);
|
|
1292
|
+
console.log(` Rules: ${m.enforcedRules.join(', ')} | ${m.antiSlopGuidance}`);
|
|
1293
|
+
if (m.licenseNote)
|
|
1294
|
+
console.log(` Note: ${m.licenseNote}`);
|
|
1295
|
+
}
|
|
1296
|
+
console.log();
|
|
1297
|
+
break;
|
|
1298
|
+
}
|
|
1299
|
+
case 'add': {
|
|
1300
|
+
const idOrPattern = args[1];
|
|
1301
|
+
if (!idOrPattern) {
|
|
1302
|
+
console.error('[ERROR] Please specify a component or pattern ID: sloppy add <library/component>');
|
|
1303
|
+
process.exit(2);
|
|
1304
|
+
}
|
|
1305
|
+
const cleanId = idOrPattern.trim();
|
|
1306
|
+
const entry = getComponentById(cleanId);
|
|
1307
|
+
const pattern = getPatternById(cleanId);
|
|
1308
|
+
const dirIdx = args.indexOf('--dir') !== -1 ? args.indexOf('--dir') : args.indexOf('--dest');
|
|
1309
|
+
const customDir = dirIdx !== -1 && args[dirIdx + 1] ? args[dirIdx + 1] : null;
|
|
1310
|
+
if (entry) {
|
|
1311
|
+
// Add component from packages/components/
|
|
1312
|
+
const srcFile = path.resolve(COMPONENTS_DIR, entry.sourcePath);
|
|
1313
|
+
if (!fs.existsSync(srcFile)) {
|
|
1314
|
+
console.error(`[ERROR] Component source not found: ${srcFile}`);
|
|
1315
|
+
process.exit(2);
|
|
1316
|
+
}
|
|
1317
|
+
const destDir = customDir
|
|
1318
|
+
? path.resolve(process.cwd(), customDir)
|
|
1319
|
+
: path.resolve(process.cwd(), 'src/components', entry.library);
|
|
1320
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
1321
|
+
const destFile = path.resolve(destDir, path.basename(srcFile));
|
|
1322
|
+
fs.copyFileSync(srcFile, destFile);
|
|
1323
|
+
console.log(`\n[SUCCESS] Installed ${entry.id} -> ${path.relative(process.cwd(), destFile)}`);
|
|
1324
|
+
console.log(`\nAnti-Slop Design Guidance:`);
|
|
1325
|
+
console.log(` ${entry.antiSlopGuidance}`);
|
|
1326
|
+
if (entry.dependencies.length > 0) {
|
|
1327
|
+
console.log(`\nRequired Dependencies:`);
|
|
1328
|
+
console.log(` npm install ${entry.dependencies.join(' ')}`);
|
|
1329
|
+
}
|
|
1330
|
+
return;
|
|
1331
|
+
}
|
|
1332
|
+
if (pattern || fs.existsSync(path.resolve(PATTERNS_DIR, cleanId))) {
|
|
1333
|
+
// Add pattern from patterns/
|
|
1334
|
+
const patternSourceDir = path.resolve(PATTERNS_DIR, cleanId);
|
|
1335
|
+
const destDir = customDir
|
|
1336
|
+
? path.resolve(process.cwd(), customDir, cleanId)
|
|
1337
|
+
: path.resolve(process.cwd(), 'src/components', cleanId);
|
|
1338
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
1339
|
+
const files = fs.readdirSync(patternSourceDir);
|
|
1340
|
+
for (const f of files) {
|
|
1341
|
+
const src = path.join(patternSourceDir, f);
|
|
1342
|
+
const dst = path.join(destDir, f);
|
|
1343
|
+
if (fs.statSync(src).isFile()) {
|
|
1344
|
+
fs.copyFileSync(src, dst);
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
console.log(`\n[SUCCESS] Pattern "${cleanId}" installed to ${path.relative(process.cwd(), destDir)}/`);
|
|
1348
|
+
if (pattern) {
|
|
1349
|
+
console.log(`Focal Point: ${pattern.focalPoint}`);
|
|
1350
|
+
}
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
console.error(`[ERROR] Item "${cleanId}" not found in catalog or patterns.`);
|
|
1354
|
+
console.log(`Run "sloppy list" to search available components and patterns.`);
|
|
1355
|
+
process.exit(2);
|
|
1356
|
+
break;
|
|
1357
|
+
}
|
|
1358
|
+
case 'init': {
|
|
1359
|
+
const fromIdx = args.indexOf('--from');
|
|
1360
|
+
if (fromIdx !== -1 && args[fromIdx + 1]) {
|
|
1361
|
+
const sourceUrl = args[fromIdx + 1];
|
|
1362
|
+
console.log(`\n======================================================`);
|
|
1363
|
+
console.log(`SLOPPY DESIGN DNA EXTRACTOR`);
|
|
1364
|
+
console.log(`Target: ${sourceUrl}`);
|
|
1365
|
+
console.log(`======================================================\n`);
|
|
1366
|
+
console.log(`Extracting typography, color tokens, and layout DNA...`);
|
|
1367
|
+
const dna = await extractDesignDna(sourceUrl);
|
|
1368
|
+
const safeConfigJson = JSON.stringify({
|
|
1369
|
+
brand: {
|
|
1370
|
+
name: String(dna.sloppyConfig.brand?.name || 'localhost').slice(0, 64),
|
|
1371
|
+
allowColors: (dna.sloppyConfig.brand?.allowColors || []).filter(c => /^#[0-9a-f]{6}$/i.test(c)),
|
|
1372
|
+
fontSans: String(dna.sloppyConfig.brand?.fontSans || '').slice(0, 80),
|
|
1373
|
+
fontMono: String(dna.sloppyConfig.brand?.fontMono || '').slice(0, 80)
|
|
1374
|
+
},
|
|
1375
|
+
rules: dna.sloppyConfig.rules || {},
|
|
1376
|
+
overrules: {}
|
|
1377
|
+
}, null, 2) + '\n';
|
|
1378
|
+
const safeDesignMd = `# Design System Specification (DESIGN.md)\n\n- **Theme Mode**: ${dna.theme === 'light' ? 'Light Mode' : 'Dark Mode'}\n- **Border Radius**: ${dna.borderRadius}\n- **Ground**: \`${dna.colors.ground}\`\n- **Accent**: \`${dna.colors.accent}\`\n- **Primary Sans**: \`${dna.fontSans}\`\n- **Monospace**: \`${dna.fontMono}\`\n`;
|
|
1379
|
+
writeFileSafe(path.resolve(process.cwd(), 'sloppy.config.json'), safeConfigJson, true);
|
|
1380
|
+
writeFileSafe(path.resolve(process.cwd(), 'DESIGN.md'), safeDesignMd, true);
|
|
1381
|
+
console.log(`[SUCCESS] Extracted design DNA from ${dna.sourceUrl}:`);
|
|
1382
|
+
console.log(` - Theme: ${dna.theme}`);
|
|
1383
|
+
console.log(` - Font Sans: ${dna.fontSans}`);
|
|
1384
|
+
console.log(` - Font Mono: ${dna.fontMono}`);
|
|
1385
|
+
console.log(` - Accent: ${dna.colors.accent}`);
|
|
1386
|
+
console.log(` - Ground: ${dna.colors.ground}`);
|
|
1387
|
+
console.log(`\nCreated files:`);
|
|
1388
|
+
console.log(` * ./sloppy.config.json (Brand tokens & 3-tier rules)`);
|
|
1389
|
+
console.log(` * ./DESIGN.md (Comprehensive design system specification)`);
|
|
1390
|
+
break;
|
|
1391
|
+
}
|
|
1392
|
+
console.log(`\n======================================================`);
|
|
1393
|
+
console.log(`SLOPPY PROJECT INITIALIZER & STACK AUTO-DETECTION`);
|
|
1394
|
+
console.log(`======================================================\n`);
|
|
1395
|
+
const stack = detectProjectStack(process.cwd());
|
|
1396
|
+
console.log(`Detected Project Stack:`);
|
|
1397
|
+
for (const item of stack.summary) {
|
|
1398
|
+
console.log(` - ${item}`);
|
|
1399
|
+
}
|
|
1400
|
+
const force = args.includes('--force');
|
|
1401
|
+
const configPath = path.resolve(process.cwd(), 'sloppy.config.json');
|
|
1402
|
+
if (writeFileSafe(configPath, JSON.stringify(stack.suggestedConfig, null, 2) + '\n', force) !== 'exists') {
|
|
1403
|
+
console.log(`\n[SUCCESS] Generated ./sloppy.config.json tailored to detected stack.`);
|
|
1404
|
+
}
|
|
1405
|
+
else {
|
|
1406
|
+
console.log(`\n[INFO] ./sloppy.config.json already exists. Pass --force to regenerate.`);
|
|
1407
|
+
}
|
|
1408
|
+
const designPath = path.resolve(process.cwd(), 'DESIGN.md');
|
|
1409
|
+
if (writeFileSafe(designPath, DESIGN_MD_TEMPLATE, force) !== 'exists') {
|
|
1410
|
+
console.log(`[SUCCESS] Generated ./DESIGN.md design contract (token lock: palette, type, radius, blur cap, signature).`);
|
|
1411
|
+
}
|
|
1412
|
+
else {
|
|
1413
|
+
console.log(`[INFO] ./DESIGN.md already exists. Pass --force to regenerate the token-lock template.`);
|
|
1414
|
+
}
|
|
1415
|
+
const destDir = path.resolve(process.cwd(), 'src/kit');
|
|
1416
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
1417
|
+
const copyRecursive = (src, dst) => {
|
|
1418
|
+
fs.mkdirSync(dst, { recursive: true });
|
|
1419
|
+
for (const item of fs.readdirSync(src)) {
|
|
1420
|
+
if (item === 'node_modules' || item === 'dist' || item === 'package.json' || item === 'tsconfig.json')
|
|
1421
|
+
continue;
|
|
1422
|
+
const s = path.join(src, item);
|
|
1423
|
+
const d = path.join(dst, item);
|
|
1424
|
+
if (fs.statSync(s).isDirectory()) {
|
|
1425
|
+
copyRecursive(s, d);
|
|
1426
|
+
}
|
|
1427
|
+
else {
|
|
1428
|
+
fs.copyFileSync(s, d);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
copyRecursive(KIT_DIR, destDir);
|
|
1433
|
+
console.log(`[SUCCESS] Sloppy Anti-Slop React Kit installed into ./src/kit/`);
|
|
1434
|
+
console.log(`Import components with: import { Stage, Window, Act, Bar } from './kit'`);
|
|
1435
|
+
break;
|
|
1436
|
+
}
|
|
1437
|
+
case 'gain': {
|
|
1438
|
+
console.log(`\n======================================================`);
|
|
1439
|
+
console.log(`SLOPPY CRAFT SCOREBOARD (MEASURED VALUE IMPACT)`);
|
|
1440
|
+
console.log(`======================================================\n`);
|
|
1441
|
+
console.log(`Eradicated Anti-Patterns (Zero-Tolerance Standards):`);
|
|
1442
|
+
console.log(` * AI Cliché & Narration: 100% stripped (COD-01, CPY-03..07)`);
|
|
1443
|
+
console.log(` * Low-Evidence TS Slop: 100% blocked in CI (COD-02..06)`);
|
|
1444
|
+
console.log(` * Unanchored Floats & Cards: Replaced with grounded stages & bleeding frames`);
|
|
1445
|
+
console.log(` * Purple & Hero Text Gradients: Eradicated; replaced with high-contrast type`);
|
|
1446
|
+
console.log(` * Dead Placeholders & Fakes: Converted to semantic controls with ARIA roles\n`);
|
|
1447
|
+
console.log(`Safety & Delivery Impact:`);
|
|
1448
|
+
console.log(` * Wiring Guard Integrity: 100% retained (zero dropped hrefs, forms, handlers)`);
|
|
1449
|
+
console.log(` * CI Floor Gates: WCAG AA contrast, touch targets, keyboard navigation`);
|
|
1450
|
+
console.log(` * Agent Token Efficiency: ~62% prompt reduction with --compact & modular skills`);
|
|
1451
|
+
console.log(` * Craft Rubric Baseline: 10/10 Master Archetypes Grade A+ (100/100)\n`);
|
|
1452
|
+
console.log(`Run 'sloppy audit --mode after' to generate surgical approval-gated reports.`);
|
|
1453
|
+
break;
|
|
1454
|
+
}
|
|
1455
|
+
case 'looks': {
|
|
1456
|
+
const isNext = args.includes('--next');
|
|
1457
|
+
if (isNext) {
|
|
1458
|
+
const theme = args.includes('--dark') ? 'dark' : args.includes('--light') ? 'light' : undefined;
|
|
1459
|
+
const material = getNextMaterial({ theme });
|
|
1460
|
+
if (json) {
|
|
1461
|
+
emitJson(material);
|
|
1462
|
+
break;
|
|
1463
|
+
}
|
|
1464
|
+
console.log(`\n======================================================`);
|
|
1465
|
+
console.log(`SLOPPY NEXT MATERIAL (Anti-Repetition Engine)`);
|
|
1466
|
+
console.log(`======================================================\n`);
|
|
1467
|
+
console.log(`Selected Material: ${material.name.toUpperCase()} [${material.theme.toUpperCase()}]`);
|
|
1468
|
+
console.log(`Description: ${material.description}`);
|
|
1469
|
+
console.log(`Surfaces: ground: ${material.background} | s1: ${material.surface1} | s2: ${material.surface2} | s3: ${material.surface3}`);
|
|
1470
|
+
console.log(`Accent: ${material.accent}`);
|
|
1471
|
+
console.log(`Border: ${material.border}`);
|
|
1472
|
+
if (material.fontSans)
|
|
1473
|
+
console.log(`Typography: ${material.fontSans}`);
|
|
1474
|
+
console.log(`\n[HISTORY UPDATED] Dealt "${material.name}". Anti-repetition tracker updated.`);
|
|
1475
|
+
break;
|
|
1476
|
+
}
|
|
1477
|
+
if (json) {
|
|
1478
|
+
emitJson(LOOKS);
|
|
1479
|
+
break;
|
|
1480
|
+
}
|
|
1481
|
+
console.log(`\n======================================================`);
|
|
1482
|
+
console.log(`SLOPPY DESIGN LOOKS & SURFACE TOKENS`);
|
|
1483
|
+
console.log(`======================================================\n`);
|
|
1484
|
+
for (const [key, look] of Object.entries(LOOKS)) {
|
|
1485
|
+
console.log(`* Look: ${look.name.toUpperCase()} [${look.theme.toUpperCase()}]`);
|
|
1486
|
+
console.log(` Description: ${look.description}`);
|
|
1487
|
+
console.log(` Accent: ${look.accent}`);
|
|
1488
|
+
console.log(` Background: ${look.background}`);
|
|
1489
|
+
console.log(` Surfaces: 1: ${look.surface1} | 2: ${look.surface2} | 3: ${look.surface3}`);
|
|
1490
|
+
console.log(` Border: ${look.border}`);
|
|
1491
|
+
if (look.fontSans)
|
|
1492
|
+
console.log(` Type: ${look.fontSans}`);
|
|
1493
|
+
if (look.source)
|
|
1494
|
+
console.log(` Source: ${look.source.site} (${look.source.url}) via Refero Styles`);
|
|
1495
|
+
console.log('');
|
|
1496
|
+
}
|
|
1497
|
+
break;
|
|
1498
|
+
}
|
|
1499
|
+
case 'hook': {
|
|
1500
|
+
const sub = args[1];
|
|
1501
|
+
if (sub === 'install') {
|
|
1502
|
+
const installScript = path.resolve(ROOT_DIR, 'scripts/install-hook.mjs');
|
|
1503
|
+
const child = spawn(process.execPath, [installScript, ...args.slice(2)], {
|
|
1504
|
+
cwd: process.cwd(),
|
|
1505
|
+
stdio: 'inherit'
|
|
1506
|
+
});
|
|
1507
|
+
child.on('exit', (code) => {
|
|
1508
|
+
process.exit(code || 0);
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
else {
|
|
1512
|
+
console.log('Usage: sloppy hook install [--cursor|--claude|--git]');
|
|
1513
|
+
}
|
|
1514
|
+
break;
|
|
1515
|
+
}
|
|
1516
|
+
case 'dev': {
|
|
1517
|
+
console.log(`Starting Sloppy Visual Playground on http://127.0.0.1:1355 ...`);
|
|
1518
|
+
const child = spawn('npx', ['vite', '--host', '127.0.0.1', '--port', '1355'], {
|
|
1519
|
+
cwd: PLAYGROUND_DIR,
|
|
1520
|
+
stdio: 'inherit',
|
|
1521
|
+
shell: true
|
|
1522
|
+
});
|
|
1523
|
+
child.on('exit', (code) => {
|
|
1524
|
+
process.exit(code || 0);
|
|
1525
|
+
});
|
|
1526
|
+
break;
|
|
1527
|
+
}
|
|
1528
|
+
case 'mcp': {
|
|
1529
|
+
await runServer();
|
|
1530
|
+
break;
|
|
1531
|
+
}
|
|
1532
|
+
case 'help':
|
|
1533
|
+
default: {
|
|
1534
|
+
console.log(`
|
|
1535
|
+
SLOPPY: The AI Slop UI Fixer (MCP + Kit + Skill Engine)
|
|
1536
|
+
Combining MIT Component Ecosystems (stageshow, shadcn, motion-primitives, magicui, kokonutui)
|
|
1537
|
+
& 21 Permissive Motion/Scroll/3D/Lottie Governors (Motion, Anime, Three.js, R3F, PixiJS, Lenis, Lottie, Rive)
|
|
1538
|
+
|
|
1539
|
+
Usage:
|
|
1540
|
+
sloppy setup [--write|-w] All-in-one setup: configure MCP clients and link Agent Skills
|
|
1541
|
+
sloppy check <paths...|url> Gate files on slop score, severity, and craft grade (--code, --compact, --render)
|
|
1542
|
+
sloppy audit <file|dir> Audit code or directory for AI slop anti-patterns (--strict, --floor-only, --code)
|
|
1543
|
+
sloppy gain Display measured craft value scoreboard & token efficiency
|
|
1544
|
+
sloppy rubric <file> Evaluate code against 10-point Craft Rubric (Grade A+ to F)
|
|
1545
|
+
sloppy plan <file> Generate structured repair plan with confidence & risk scores
|
|
1546
|
+
sloppy fix <file> [--diff|--check|--write] Review or apply a proposed repair
|
|
1547
|
+
sloppy fix --stdin [--json] Transform source from stdin
|
|
1548
|
+
sloppy verify [target] Run browser or static verification (--multi-width, --static)
|
|
1549
|
+
sloppy rules List canonical rule IDs with tier, severity, and auto-fix/detect-only mode
|
|
1550
|
+
sloppy install-mcp --client <client> Configure an MCP client
|
|
1551
|
+
sloppy version [--json] Show CLI and core versions
|
|
1552
|
+
sloppy create <archetype> Scaffold a unified multi-library master archetype
|
|
1553
|
+
sloppy archetypes List 10 available multi-library master archetypes
|
|
1554
|
+
sloppy list [library] List all components or filter by library
|
|
1555
|
+
sloppy libs Show the 7 integrated UI libraries and their design roles
|
|
1556
|
+
sloppy add <componentId> Install a component directly into your project
|
|
1557
|
+
sloppy init Scaffold the anti-slop React kit into ./src/kit/
|
|
1558
|
+
sloppy looks View available design looks and token scales
|
|
1559
|
+
sloppy dev Launch visual playground on http://127.0.0.1:1355
|
|
1560
|
+
sloppy mcp Start the stdio Model Context Protocol server
|
|
1561
|
+
sloppy help Show this help screen
|
|
1562
|
+
`);
|
|
1563
|
+
break;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
//# sourceMappingURL=index.js.map
|