@shavin/skills 0.0.0-stage → 0.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/AGENTS.md +193 -0
- package/CHANGELOG.md +27 -0
- package/LICENSE +21 -0
- package/README.md +48 -2
- package/bin/hex-policy.mjs +157 -0
- package/bin/install.mjs +219 -0
- package/bin/lint-tokens.mjs +178 -0
- package/build.mjs +540 -0
- package/commands/add-composition.md +14 -0
- package/commands/apply-theme.md +59 -0
- package/commands/audit-layout.md +15 -0
- package/commands/audit-ui.md +42 -0
- package/commands/compose-page.md +16 -0
- package/commands/create-block.md +79 -0
- package/commands/create-primitive.md +40 -0
- package/commands/create-screen.md +45 -0
- package/commands/create-theme.md +41 -0
- package/cursor/shavin.mdc +14 -0
- package/package.json +66 -4
- package/posix-path.mjs +7 -0
- package/skills/core-rules.md +294 -0
- package/skills/layout-choreography/SKILL.md +102 -0
- package/skills/layout-choreography/references/fallbacks-and-accessibility.md +76 -0
- package/skills/layout-choreography/references/scenes.md +113 -0
- package/skills/layout-choreography/references/shavin-timelines.md +100 -0
- package/skills/layout-choreography/references/tech-and-performance.md +147 -0
- package/skills/layout-compositions/SKILL.md +149 -0
- package/skills/layout-compositions/references/adapters/shavin-ui.md +122 -0
- package/skills/layout-compositions/references/adapters/tailwind-html.md +100 -0
- package/skills/layout-compositions/references/component-language.md +105 -0
- package/skills/layout-compositions/references/compositions/conversion.md +286 -0
- package/skills/layout-compositions/references/compositions/documentation.md +125 -0
- package/skills/layout-compositions/references/compositions/editorial.md +126 -0
- package/skills/layout-compositions/references/compositions/expressive.md +151 -0
- package/skills/layout-compositions/references/compositions/features.md +262 -0
- package/skills/layout-compositions/references/compositions/gallery.md +172 -0
- package/skills/layout-compositions/references/compositions/hero.md +184 -0
- package/skills/layout-compositions/references/compositions/proof.md +194 -0
- package/skills/layout-compositions/references/compositions/structural.md +173 -0
- package/skills/layout-compositions/references/distinctiveness.md +65 -0
- package/skills/layout-compositions/references/foundations.md +119 -0
- package/skills/layout-compositions/references/metadata-schema.md +64 -0
- package/skills/layout-compositions/references/page-recipes.md +143 -0
- package/skills/layout-compositions/references/selection-guide.md +207 -0
- package/skills/layout-compositions/references/treatments.md +60 -0
- package/skills/layout-compositions/references/unsection-source-examples.md +92 -0
- package/skills/layout-compositions/references/visual-review.md +40 -0
- package/skills/layout-compositions/scripts/render_wireframes.py +138 -0
- package/skills/layout-compositions/scripts/validate_library.py +165 -0
- package/skills/layout-motion/SKILL.md +83 -0
- package/skills/layout-motion/references/composition-motion-map.md +69 -0
- package/skills/layout-motion/references/presets.md +209 -0
- package/skills/layout-motion/references/tokens.md +100 -0
- package/skills/shavin-app/SKILL.md +242 -0
- package/skills/shavin-app/patterns.md +35 -0
- package/skills/shavin-studio/SKILL.md +97 -0
- package/skills/shavin-webpage/SKILL.md +210 -0
- package/skills/shavin-webpage/editorial-craft.md +117 -0
- package/skills/shavin-webpage/page-architecture.md +137 -0
- package/skills/shavin-webpage/style-recipes.md +107 -0
- package/skills/visual-compositor/SKILL.md +200 -0
- package/skills/visual-compositor/anti-patterns.md +109 -0
- package/skills/visual-compositor/audit-checklist.md +162 -0
- package/skills/visual-compositor/cognitive-layer.md +287 -0
- package/skills/visual-compositor/composition-motion-map.md +167 -0
- package/skills/visual-compositor/concentric-laws.md +147 -0
- package/skills/visual-compositor/docs-mode.md +32 -0
- package/skills/visual-compositor/editorial-mode.md +48 -0
- package/skills/visual-compositor/font-pairings.md +224 -0
- package/skills/visual-compositor/graphics-and-assets.md +128 -0
- package/skills/visual-compositor/interface-polish.md +125 -0
- package/skills/visual-compositor/layout-restraint.md +80 -0
- package/skills/visual-compositor/motion-and-physics.md +257 -0
- package/skills/visual-compositor/page-motion-presets.md +246 -0
- package/skills/visual-compositor/references/EDITORIAL_EXPRESSIVE.md +163 -0
- package/skills/visual-compositor/spacing-core.md +386 -0
- package/skills/visual-compositor/spacing-dense.md +63 -0
- package/skills/visual-compositor/spacing-marketing.md +192 -0
- package/skills/visual-compositor/typography-rules.md +114 -0
- package/token-budget.json +86 -0
package/bin/install.mjs
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @shavin/skills — Skill & Command Installer
|
|
5
|
+
*
|
|
6
|
+
* Copies bundled skill and command .md files from this package into the user's
|
|
7
|
+
* project at .agents/skills/ and .agents/commands/ (Codex, Cursor and other tools that
|
|
8
|
+
* read .agents/), and at .claude/skills/ and .claude/commands/ (Claude Code, which reads
|
|
9
|
+
* only those folders). Writes .cursor/rules/shavin.mdc (an always-on Cursor rule). Also
|
|
10
|
+
* refreshes the Shavin block in AGENTS.md (without overwriting the rest of it).
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* npx @shavin/skills # install skills & commands
|
|
14
|
+
* npx @shavin/skills --force # overwrite existing files
|
|
15
|
+
* npx @shavin/skills --target ./apps/myapp # install to a specific project
|
|
16
|
+
* npx @shavin/skills --no-claude # skip .claude/skills and .claude/commands
|
|
17
|
+
* npx @shavin/skills --no-cursor # skip .cursor/rules/shavin.mdc
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, statSync } from "node:fs";
|
|
21
|
+
import { resolve, join, dirname } from "node:path";
|
|
22
|
+
import { fileURLToPath } from "node:url";
|
|
23
|
+
|
|
24
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
const __dirname = dirname(__filename);
|
|
26
|
+
const PKG_ROOT = resolve(__dirname, "..");
|
|
27
|
+
const SKILLS_SRC = resolve(PKG_ROOT, "skills");
|
|
28
|
+
const COMMANDS_SRC = resolve(PKG_ROOT, "commands");
|
|
29
|
+
const CURSOR_RULE_SRC = resolve(PKG_ROOT, "cursor", "shavin.mdc");
|
|
30
|
+
|
|
31
|
+
// --- Parse args ---
|
|
32
|
+
const args = process.argv.slice(2);
|
|
33
|
+
|
|
34
|
+
// --help prints the usage and installs nothing.
|
|
35
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
36
|
+
console.log(`@shavin/skills: install the Shavin agent skills and slash commands into a project
|
|
37
|
+
|
|
38
|
+
Usage:
|
|
39
|
+
npx @shavin/skills install skills and commands into the current folder
|
|
40
|
+
npx @shavin/skills --force overwrite existing files
|
|
41
|
+
npx @shavin/skills --target ./apps/myapp install into a specific project
|
|
42
|
+
npx @shavin/skills --no-claude skip .claude/skills and .claude/commands
|
|
43
|
+
npx @shavin/skills --no-cursor skip .cursor/rules/shavin.mdc
|
|
44
|
+
npx @shavin/skills --help show this help`);
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
const force = args.includes("--force") || args.includes("-f");
|
|
48
|
+
const noClaude = args.includes("--no-claude");
|
|
49
|
+
const noCursor = args.includes("--no-cursor");
|
|
50
|
+
const targetIdx = args.indexOf("--target");
|
|
51
|
+
const nonFlagArgs = args.filter((a, i) => !a.startsWith("-") && !(targetIdx !== -1 && i === targetIdx + 1));
|
|
52
|
+
const targetDir = targetIdx !== -1 && args[targetIdx + 1]
|
|
53
|
+
? resolve(args[targetIdx + 1])
|
|
54
|
+
: nonFlagArgs.length > 0
|
|
55
|
+
? resolve(nonFlagArgs[0])
|
|
56
|
+
: process.cwd();
|
|
57
|
+
|
|
58
|
+
// --- Skills that are never installed into a project (none today) ---
|
|
59
|
+
// Maintainer-only skills (packages/skills/internal.json) are never installed into a project.
|
|
60
|
+
const INTERNAL_ONLY_SKILLS = new Set(
|
|
61
|
+
(() => { try { return JSON.parse(readFileSync(resolve(PKG_ROOT, "internal.json"), "utf8")).maintainerOnly.map((e) => e.path); } catch { return []; } })(),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// --- Helpers ---
|
|
65
|
+
function copyDir(src, dst) {
|
|
66
|
+
let count = 0;
|
|
67
|
+
if (!existsSync(src)) return 0;
|
|
68
|
+
|
|
69
|
+
for (const entry of readdirSync(src)) {
|
|
70
|
+
if (INTERNAL_ONLY_SKILLS.has(entry)) continue;
|
|
71
|
+
const srcPath = join(src, entry);
|
|
72
|
+
const dstPath = join(dst, entry);
|
|
73
|
+
|
|
74
|
+
if (statSync(srcPath).isDirectory()) {
|
|
75
|
+
if (!existsSync(dstPath)) mkdirSync(dstPath, { recursive: true });
|
|
76
|
+
count += copyDir(srcPath, dstPath);
|
|
77
|
+
} else if (entry.endsWith(".md") || entry.endsWith(".py")) { // .py: catalogue helper scripts
|
|
78
|
+
if (existsSync(dstPath) && !force) {
|
|
79
|
+
// Skip existing unless --force
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
writeFileSync(dstPath, readFileSync(srcPath, "utf8"), "utf8");
|
|
83
|
+
count++;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return count;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// --- Banner ---
|
|
90
|
+
console.log("\x1b[36m%s\x1b[0m", "\n🎨 @shavin/skills — AI Agent Skill & Command Installer\n");
|
|
91
|
+
|
|
92
|
+
// --- Validate source ---
|
|
93
|
+
if (!existsSync(SKILLS_SRC)) {
|
|
94
|
+
console.error("\x1b[31m%s\x1b[0m", "✗ No skills/ directory found in package. This should not happen — please report this issue.");
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// --- Count source files ---
|
|
99
|
+
function countMd(dir) {
|
|
100
|
+
let n = 0;
|
|
101
|
+
if (!existsSync(dir)) return 0;
|
|
102
|
+
for (const entry of readdirSync(dir)) {
|
|
103
|
+
if (INTERNAL_ONLY_SKILLS.has(entry)) continue;
|
|
104
|
+
const p = join(dir, entry);
|
|
105
|
+
if (statSync(p).isDirectory()) n += countMd(p);
|
|
106
|
+
else if (entry.endsWith(".md")) n++;
|
|
107
|
+
}
|
|
108
|
+
return n;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const sourceSkillsCount = countMd(SKILLS_SRC);
|
|
112
|
+
const sourceCommandsCount = countMd(COMMANDS_SRC);
|
|
113
|
+
console.log(` Source: ${sourceSkillsCount} skill files + ${sourceCommandsCount} commands from @shavin/skills`);
|
|
114
|
+
console.log(` Target: ${targetDir}/.agents/`);
|
|
115
|
+
|
|
116
|
+
// --- Copy skills ---
|
|
117
|
+
const targetSkillsDir = resolve(targetDir, ".agents", "skills");
|
|
118
|
+
if (!existsSync(targetSkillsDir)) mkdirSync(targetSkillsDir, { recursive: true });
|
|
119
|
+
|
|
120
|
+
const copiedSkills = copyDir(SKILLS_SRC, targetSkillsDir);
|
|
121
|
+
|
|
122
|
+
if (copiedSkills === 0 && !force) {
|
|
123
|
+
console.log("\x1b[33m%s\x1b[0m", "\n ⚠ All skill files already exist. Use --force to overwrite.");
|
|
124
|
+
} else {
|
|
125
|
+
console.log("\x1b[32m%s\x1b[0m", `\n ✓ Deployed ${copiedSkills} skill file(s) to .agents/skills/`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// --- Copy commands ---
|
|
129
|
+
let copiedCommands = 0;
|
|
130
|
+
if (existsSync(COMMANDS_SRC)) {
|
|
131
|
+
const targetCommandsDir = resolve(targetDir, ".agents", "commands");
|
|
132
|
+
if (!existsSync(targetCommandsDir)) mkdirSync(targetCommandsDir, { recursive: true });
|
|
133
|
+
copiedCommands = copyDir(COMMANDS_SRC, targetCommandsDir);
|
|
134
|
+
|
|
135
|
+
if (copiedCommands > 0) {
|
|
136
|
+
console.log("\x1b[32m%s\x1b[0m", ` ✓ Deployed ${copiedCommands} AI slash command(s) to .agents/commands/`);
|
|
137
|
+
} else if (!force) {
|
|
138
|
+
console.log("\x1b[33m%s\x1b[0m", " ⚠ All command files already exist. Use --force to overwrite.");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// --- Claude Code: .claude/skills/<name>/SKILL.md and .claude/commands/*.md ---
|
|
143
|
+
// Claude Code reads only these folders (not .agents/). Same files, so the relative links between skills still work.
|
|
144
|
+
let claudeSkills = 0, claudeCommands = 0;
|
|
145
|
+
if (!noClaude) {
|
|
146
|
+
const claudeSkillsDir = resolve(targetDir, ".claude", "skills");
|
|
147
|
+
mkdirSync(claudeSkillsDir, { recursive: true });
|
|
148
|
+
claudeSkills = copyDir(SKILLS_SRC, claudeSkillsDir);
|
|
149
|
+
if (existsSync(COMMANDS_SRC)) {
|
|
150
|
+
const claudeCommandsDir = resolve(targetDir, ".claude", "commands");
|
|
151
|
+
mkdirSync(claudeCommandsDir, { recursive: true });
|
|
152
|
+
claudeCommands = copyDir(COMMANDS_SRC, claudeCommandsDir);
|
|
153
|
+
}
|
|
154
|
+
console.log("\x1b[32m%s\x1b[0m", ` ✓ Deployed ${claudeSkills} skill file(s) and ${claudeCommands} command(s) to .claude/ (Claude Code)`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// --- Cursor: one always-on rule ---
|
|
158
|
+
let cursorRule = false;
|
|
159
|
+
if (!noCursor && existsSync(CURSOR_RULE_SRC)) {
|
|
160
|
+
const dst = resolve(targetDir, ".cursor", "rules", "shavin.mdc");
|
|
161
|
+
if (!existsSync(dst) || force) {
|
|
162
|
+
mkdirSync(dirname(dst), { recursive: true });
|
|
163
|
+
writeFileSync(dst, readFileSync(CURSOR_RULE_SRC, "utf8"), "utf8");
|
|
164
|
+
cursorRule = true;
|
|
165
|
+
console.log("\x1b[32m%s\x1b[0m", " ✓ Wrote .cursor/rules/shavin.mdc (Cursor)");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// --- List deployed files ---
|
|
170
|
+
function listFiles(dir, prefix = "") {
|
|
171
|
+
if (!existsSync(dir)) return;
|
|
172
|
+
for (const entry of readdirSync(dir).sort()) {
|
|
173
|
+
const p = join(dir, entry);
|
|
174
|
+
if (statSync(p).isDirectory()) {
|
|
175
|
+
listFiles(p, `${prefix}${entry}/`);
|
|
176
|
+
} else if (entry.endsWith(".md")) {
|
|
177
|
+
console.log(`\x1b[2m%s\x1b[0m`, ` ${prefix}${entry}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
console.log("\x1b[2m%s\x1b[0m", "\n Deployed files:");
|
|
182
|
+
listFiles(targetSkillsDir, "skills/");
|
|
183
|
+
if (existsSync(resolve(targetDir, ".agents", "commands"))) {
|
|
184
|
+
listFiles(resolve(targetDir, ".agents", "commands"), "commands/");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// --- AGENTS.md: the generated rules ship in this package (AGENTS.md). A missing file is
|
|
188
|
+
// created; an existing one gets (or refreshes) only the marked skills block, so a project's
|
|
189
|
+
// own content is never overwritten.
|
|
190
|
+
const MARK = "<!-- @shavin/skills:reference -->";
|
|
191
|
+
const MARK_END = "<!-- @shavin/skills:reference-end -->";
|
|
192
|
+
const pkgAgentsPath = resolve(PKG_ROOT, "AGENTS.md");
|
|
193
|
+
const agentsMdPath = resolve(targetDir, "AGENTS.md");
|
|
194
|
+
if (existsSync(pkgAgentsPath)) {
|
|
195
|
+
const fresh = readFileSync(pkgAgentsPath, "utf8");
|
|
196
|
+
const block = fresh.slice(fresh.indexOf(MARK), fresh.indexOf(MARK_END) + MARK_END.length);
|
|
197
|
+
if (!existsSync(agentsMdPath)) {
|
|
198
|
+
writeFileSync(agentsMdPath, fresh, "utf8");
|
|
199
|
+
console.log("\x1b[32m%s\x1b[0m", "\n ✓ Created AGENTS.md (Shavin rules + skills guide)");
|
|
200
|
+
} else {
|
|
201
|
+
const current = readFileSync(agentsMdPath, "utf8");
|
|
202
|
+
const s0 = current.indexOf(MARK), e0 = current.indexOf(MARK_END);
|
|
203
|
+
const next = s0 !== -1 && e0 !== -1
|
|
204
|
+
? current.slice(0, s0) + block + current.slice(e0 + MARK_END.length)
|
|
205
|
+
: current.trimEnd() + "\n\n" + block + "\n";
|
|
206
|
+
if (next !== current) {
|
|
207
|
+
writeFileSync(agentsMdPath, next, "utf8");
|
|
208
|
+
console.log("\x1b[32m%s\x1b[0m", s0 !== -1 ? "\n ✓ Refreshed the Shavin skills block in AGENTS.md" : "\n ✓ Appended the Shavin skills block to AGENTS.md");
|
|
209
|
+
} else {
|
|
210
|
+
console.log("\x1b[2m%s\x1b[0m", "\n • AGENTS.md skills block is up to date");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
console.log("\x1b[32m%s\x1b[0m", "\n✨ @shavin/skills installation complete!\n");
|
|
216
|
+
console.log("\x1b[36m%s\x1b[0m", ` • Skills ready: .agents/skills/${noClaude ? "" : " and .claude/skills/"}`);
|
|
217
|
+
console.log("\x1b[36m%s\x1b[0m", ` • Slash commands ready: .agents/commands/ (${readdirSync(COMMANDS_SRC).filter((f) => f.endsWith(".md")).map((f) => "/" + f.slice(0, -3)).join(", ")})`);
|
|
218
|
+
console.log("\x1b[36m%s\x1b[0m", " • Primary brain: SHAVIN.md");
|
|
219
|
+
console.log("\x1b[36m%s\x1b[0m", " • Update anytime: npx @shavin/skills --force\n");
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* bin/lint-tokens.mjs
|
|
4
|
+
*
|
|
5
|
+
* Deterministic, MCP-independent equivalent of @shavin/mcp's `validate_code` /
|
|
6
|
+
* `autofix_code` tools. The regexes below are copied verbatim from
|
|
7
|
+
* mcp-server/src/tools/validation.mjs so that a No-MCP install (this package
|
|
8
|
+
* has zero runtime dependency on @shavin/mcp — see package.json) gets the
|
|
9
|
+
* same enforcement an MCP-connected agent would get via `validate_code`,
|
|
10
|
+
* instead of falling back to a purely self-graded checklist.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* node bin/lint-tokens.mjs <file-or-glob> [--fix] [--dense]
|
|
14
|
+
*
|
|
15
|
+
* Exit code: 0 if clean (or after --fix), 1 if violations remain.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { globSync } from "node:fs";
|
|
20
|
+
import { findHexViolations, matchHexColors } from "./hex-policy.mjs";
|
|
21
|
+
|
|
22
|
+
function validateCode(code) {
|
|
23
|
+
const violations = [];
|
|
24
|
+
// Media overlay scrims carry data-overlay="true" — intentional, skip those lines.
|
|
25
|
+
// Also strip bgOverlays/bgImage/bgVideo prop values — they contain hex colors
|
|
26
|
+
// and rgba() as DATA for the bg-media feature, not styling. Users intentionally
|
|
27
|
+
// try different color shades to enhance background media.
|
|
28
|
+
code = code.split(/\r?\n/)
|
|
29
|
+
.filter((l) => !/data-overlay/.test(l))
|
|
30
|
+
.map((l) => l.replace(/\bbg(Overlays|Image|Video)\s*=\s*(?:"[^"]*"|'[^']*'|`[^`]*`)/g, "bg$1=\"\""))
|
|
31
|
+
// brandColor="#hex" on ThemeProvider / ScopedThemeProvider is where a custom brand colour belongs: the value
|
|
32
|
+
// `shavin brand` writes into the root layout. Same exemption as validate_code in @shavin/mcp.
|
|
33
|
+
.map((l) => l.replace(/\bbrandColor\s*=\s*(?:"[^"]*"|'[^']*'|\{\s*(?:"[^"]*"|'[^']*')\s*\})/g, 'brandColor="brand"'))
|
|
34
|
+
.join("\n");
|
|
35
|
+
|
|
36
|
+
const hexMatches = matchHexColors(code);
|
|
37
|
+
if (hexMatches.length > 0) {
|
|
38
|
+
violations.push(
|
|
39
|
+
`Hardcoded hex colors found: ${hexMatches.join(", ")}. Use semantic token utilities (bg-surface, text-fg, border-hairline, …) instead.`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (/rgb\s*\(|rgba\s*\(/.test(code)) {
|
|
44
|
+
violations.push("Raw rgb()/rgba() literals found. Use semantic CSS custom properties via Tailwind utilities instead.");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const foundationVars = code.match(/--n-\d+/g) ?? [];
|
|
48
|
+
if (foundationVars.length > 0) {
|
|
49
|
+
violations.push(`Direct foundation variable references found: ${foundationVars.join(", ")}. Nothing outside global.css should reference --n-* directly.`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Standalone copy: the shared engine is packages/mcp-server/src/tools/concentric-lint.mjs. rounded-full is
|
|
53
|
+
// legitimate (pills, avatars) and is not flagged here, matching the engine.
|
|
54
|
+
const rawRadius = code.match(/\brounded-(sm|md|lg|xl|2xl|3xl)\b/g) ?? [];
|
|
55
|
+
const radiusInClasses = rawRadius.filter((m) => !/import|type|interface/.test(code));
|
|
56
|
+
if (radiusInClasses.length > 0) {
|
|
57
|
+
violations.push(
|
|
58
|
+
`Literal radius utilities found: ${radiusInClasses.join(", ")}. Use rounded-[var(--radius-lg)] or rounded-[var(--radius-panel)].`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const rawColors = code.match(
|
|
63
|
+
/\b(bg|text|border|ring|fill|stroke)-(slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-\d{2,3}\b/g
|
|
64
|
+
) ?? [];
|
|
65
|
+
if (rawColors.length > 0) {
|
|
66
|
+
violations.push(
|
|
67
|
+
`Raw Tailwind color scale utilities found: ${rawColors.join(", ")}. Use semantic utilities (bg-surface, text-fg, text-fg-muted, border-hairline, bg-brand, …) instead.`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return violations;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function autofixCode(code) {
|
|
75
|
+
let fixedCode = code;
|
|
76
|
+
const fixesApplied = [];
|
|
77
|
+
// Only rewrite hex the shared policy calls a colour — never ids in copy.
|
|
78
|
+
let colorAt = new Set(findHexViolations(code).map((v) => v.index));
|
|
79
|
+
|
|
80
|
+
fixedCode = fixedCode.replace(/#ffffff|#fff\b/gi, (match, offset, str) => {
|
|
81
|
+
// skip intentional media-overlay scrim lines (data-overlay="true")
|
|
82
|
+
const lineStart = str.lastIndexOf("\n", offset) + 1;
|
|
83
|
+
const line = str.slice(lineStart, offset + match.length);
|
|
84
|
+
if (/data-overlay/.test(line)) return match;
|
|
85
|
+
// skip hex inside bgOverlays/bgImage/bgVideo prop values — DATA for bg-media
|
|
86
|
+
if (/bg(Overlays|Image|Video)\s*=/.test(line)) return match;
|
|
87
|
+
// skip the brandColor value of ThemeProvider: that hex is the brand choice itself
|
|
88
|
+
if (/\bbrandColor\s*=\s*\{?\s*["'][^"']*$/.test(line)) return match;
|
|
89
|
+
if (!colorAt.has(offset)) return match;
|
|
90
|
+
fixesApplied.push("Replaced white hex with bg-surface / text-fg");
|
|
91
|
+
return "var(--bg-surface)";
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
colorAt = new Set(findHexViolations(fixedCode).map((v) => v.index));
|
|
95
|
+
fixedCode = fixedCode.replace(/#000000|#000\b/gi, (match, offset, str) => {
|
|
96
|
+
const lineStart = str.lastIndexOf("\n", offset) + 1;
|
|
97
|
+
const line = str.slice(lineStart, offset + match.length);
|
|
98
|
+
if (/data-overlay/.test(line)) return match;
|
|
99
|
+
// skip hex inside bgOverlays/bgImage/bgVideo prop values — DATA for bg-media
|
|
100
|
+
if (/bg(Overlays|Image|Video)\s*=/.test(line)) return match;
|
|
101
|
+
// skip the brandColor value of ThemeProvider: that hex is the brand choice itself
|
|
102
|
+
if (/\bbrandColor\s*=\s*\{?\s*["'][^"']*$/.test(line)) return match;
|
|
103
|
+
if (!colorAt.has(offset)) return match;
|
|
104
|
+
fixesApplied.push("Replaced black hex with text-fg");
|
|
105
|
+
return "var(--fg)";
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// rounded-lg/xl/2xl/3xl are reported but not auto-fixed here: the right replacement depends on role
|
|
109
|
+
// (control -> --radius-lg, container -> --radius-panel, nested -> rounded-panel-pN), which only the
|
|
110
|
+
// engine in packages/mcp-server/src/tools/concentric-lint.mjs (validate_code / autofix_code) can judge.
|
|
111
|
+
|
|
112
|
+
fixedCode = fixedCode.replace(/\brounded-(sm|md)\b/g, (match) => {
|
|
113
|
+
fixesApplied.push(`Replaced literal ${match} with rounded-[var(--radius-lg)]`);
|
|
114
|
+
return "rounded-[var(--radius-lg)]";
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return { fixedCode, fixesApplied };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const args = process.argv.slice(2);
|
|
121
|
+
const doFix = args.includes("--fix");
|
|
122
|
+
const dense = args.includes("--dense");
|
|
123
|
+
const targets = args.filter((a) => !a.startsWith("--"));
|
|
124
|
+
|
|
125
|
+
if (targets.length === 0) {
|
|
126
|
+
console.error("Usage: node bin/lint-tokens.mjs <file-or-glob> [--fix] [--dense]");
|
|
127
|
+
process.exit(2);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let files = [];
|
|
131
|
+
for (const t of targets) {
|
|
132
|
+
try {
|
|
133
|
+
files.push(...globSync(t));
|
|
134
|
+
} catch {
|
|
135
|
+
files.push(t);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
files = [...new Set(files)];
|
|
139
|
+
|
|
140
|
+
let hadViolations = false;
|
|
141
|
+
|
|
142
|
+
for (const file of files) {
|
|
143
|
+
let code;
|
|
144
|
+
try {
|
|
145
|
+
code = readFileSync(file, "utf8");
|
|
146
|
+
} catch {
|
|
147
|
+
console.error(`Could not read ${file}`);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const violations = validateCode(code);
|
|
152
|
+
|
|
153
|
+
if (violations.length === 0) {
|
|
154
|
+
if (!dense) console.log(`PASS ${file}`);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
hadViolations = true;
|
|
159
|
+
|
|
160
|
+
if (dense) {
|
|
161
|
+
console.log(`FAIL (${violations.length}) ${file}`);
|
|
162
|
+
} else {
|
|
163
|
+
console.log(`\n⚠ ${file} — ${violations.length} violation(s):`);
|
|
164
|
+
violations.forEach((v, i) => console.log(` ${i + 1}. ${v}`));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (doFix) {
|
|
168
|
+
const { fixedCode, fixesApplied } = autofixCode(code);
|
|
169
|
+
if (fixesApplied.length > 0) {
|
|
170
|
+
writeFileSync(file, fixedCode, "utf8");
|
|
171
|
+
console.log(` Applied ${fixesApplied.length} autofix(es) to ${file}:`);
|
|
172
|
+
fixesApplied.forEach((f) => console.log(` - ${f}`));
|
|
173
|
+
console.log(" (raw Tailwind color-scale utilities and foundation vars are NOT autofixed — fix those by hand)");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
process.exit(hadViolations && !doFix ? 1 : 0);
|