Forked from brdcastro/maestro
"use strict";
/**
* @file Design systems catalog — 70 real-world DESIGN.md files from nexu-io/open-design.
* The model auto-selects the best match based on conversation context.
*
* Source migration note: previously sourced from VoltAgent/awesome-design-md, which
* migrated content off GitHub to getdesign.md and broke the raw fetches. open-design
* preserves the original numbered-H2 format the truncation logic expects, plus 12
* additional brands (binance, bugatti, mastercard, meta, nike, playstation, shopify,
* starbucks, theverge, vodafone, wired, warm-editorial).
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.setDesignSystemLimit = setDesignSystemLimit;
exports.createDesignSystemTools = createDesignSystemTools;
const sdk_1 = require("@lmstudio/sdk");
const zod_1 = require("zod");
const promises_1 = require("fs/promises");
const path_1 = require("path");
const os = __importStar(require("os"));
const REPO_RAW_BASE = "https://raw.githubusercontent.com/nexu-io/open-design/main/design-systems";
const FETCH_TIMEOUT_MS = 10_000;
/** Configurable max chars for design system content. Set via setDesignSystemLimit(). */
let _maxDesignChars = 8_000;
function setDesignSystemLimit(limit) { _maxDesignChars = limit; }
const DESIGN_SYSTEMS = [
// AI & Machine Learning
{ id: "claude", name: "Claude", category: "AI", keywords: ["anthropic", "ai", "chat", "clean", "warm"] },
{ id: "cohere", name: "Cohere", category: "AI", keywords: ["ai", "nlp", "enterprise", "coral"] },
{ id: "elevenlabs", name: "ElevenLabs", category: "AI", keywords: ["ai", "audio", "voice", "dark", "futuristic"] },
{ id: "minimax", name: "Minimax", category: "AI", keywords: ["ai", "generative", "gradient"] },
{ id: "mistral-ai", name: "Mistral AI", category: "AI", keywords: ["ai", "open-source", "orange", "bold"] },
{ id: "ollama", name: "Ollama", category: "AI", keywords: ["ai", "local", "minimal", "terminal"] },
{ id: "opencode-ai", name: "OpenCode AI", category: "AI", keywords: ["ai", "code", "developer"] },
{ id: "replicate", name: "Replicate", category: "AI", keywords: ["ai", "api", "models", "clean"] },
{ id: "runwayml", name: "RunwayML", category: "AI", keywords: ["ai", "video", "creative", "cinematic", "dark", "film"] },
{ id: "together-ai", name: "Together AI", category: "AI", keywords: ["ai", "inference", "gradient", "purple"] },
{ id: "voltagent", name: "VoltAgent", category: "AI", keywords: ["ai", "agent", "framework", "green"] },
{ id: "x-ai", name: "xAI", category: "AI", keywords: ["ai", "grok", "dark", "futuristic", "elon"] },
// Developer Tools
{ id: "cursor", name: "Cursor", category: "Developer", keywords: ["ide", "code", "editor", "dark", "modern"] },
{ id: "expo", name: "Expo", category: "Developer", keywords: ["react-native", "mobile", "app", "blue"] },
{ id: "linear-app", name: "Linear", category: "Developer", keywords: ["project", "management", "minimal", "clean", "purple"] },
{ id: "lovable", name: "Lovable", category: "Developer", keywords: ["ai", "builder", "friendly", "pink"] },
{ id: "mintlify", name: "Mintlify", category: "Developer", keywords: ["docs", "documentation", "green", "clean"] },
{ id: "posthog", name: "PostHog", category: "Developer", keywords: ["analytics", "product", "quirky", "hedgehog"] },
{ id: "raycast", name: "Raycast", category: "Developer", keywords: ["launcher", "productivity", "dark", "gradient"] },
{ id: "resend", name: "Resend", category: "Developer", keywords: ["email", "api", "minimal", "clean"] },
{ id: "sentry", name: "Sentry", category: "Developer", keywords: ["errors", "monitoring", "dark", "purple"] },
{ id: "supabase", name: "Supabase", category: "Developer", keywords: ["database", "backend", "green", "dark"] },
{ id: "superhuman", name: "Superhuman", category: "Developer", keywords: ["email", "productivity", "luxurious", "fast"] },
{ id: "vercel", name: "Vercel", category: "Developer", keywords: ["deploy", "frontend", "black", "white", "minimal", "clean"] },
{ id: "warp", name: "Warp", category: "Developer", keywords: ["terminal", "dark", "gradient", "modern"] },
{ id: "zapier", name: "Zapier", category: "Developer", keywords: ["automation", "workflows", "orange", "friendly"] },
// Infrastructure
{ id: "clickhouse", name: "ClickHouse", category: "Infrastructure", keywords: ["database", "analytics", "yellow"] },
{ id: "composio", name: "Composio", category: "Infrastructure", keywords: ["integration", "api", "purple"] },
{ id: "hashicorp", name: "HashiCorp", category: "Infrastructure", keywords: ["cloud", "infrastructure", "black", "white"] },
{ id: "mongodb", name: "MongoDB", category: "Infrastructure", keywords: ["database", "nosql", "green"] },
{ id: "sanity", name: "Sanity", category: "Infrastructure", keywords: ["cms", "content", "red", "creative"] },
{ id: "stripe", name: "Stripe", category: "Infrastructure", keywords: ["payments", "fintech", "purple", "gradient", "polished"] },
// Design & Productivity
{ id: "airtable", name: "Airtable", category: "Design", keywords: ["spreadsheet", "database", "colorful", "friendly"] },
{ id: "cal", name: "Cal.com", category: "Design", keywords: ["calendar", "scheduling", "clean"] },
{ id: "clay", name: "Clay", category: "Design", keywords: ["crm", "networking", "warm", "organic"] },
{ id: "figma", name: "Figma", category: "Design", keywords: ["design", "ui", "collaborative", "colorful", "creative"] },
{ id: "framer", name: "Framer", category: "Design", keywords: ["design", "web", "animation", "modern", "bold"] },
{ id: "intercom", name: "Intercom", category: "Design", keywords: ["support", "chat", "friendly", "blue"] },
{ id: "miro", name: "Miro", category: "Design", keywords: ["whiteboard", "collaboration", "yellow", "creative"] },
{ id: "notion", name: "Notion", category: "Design", keywords: ["notes", "wiki", "minimal", "clean", "elegant", "editorial"] },
{ id: "pinterest", name: "Pinterest", category: "Design", keywords: ["images", "visual", "gallery", "red", "creative", "mood"] },
{ id: "webflow", name: "Webflow", category: "Design", keywords: ["web", "design", "builder", "blue", "professional"] },
// Fintech
{ id: "binance", name: "Binance", category: "Fintech", keywords: ["crypto", "exchange", "yellow", "dark", "trading"] },
{ id: "coinbase", name: "Coinbase", category: "Fintech", keywords: ["crypto", "finance", "blue", "trust"] },
{ id: "kraken", name: "Kraken", category: "Fintech", keywords: ["crypto", "exchange", "purple", "dark"] },
{ id: "mastercard", name: "Mastercard", category: "Fintech", keywords: ["payments", "card", "circles", "red", "yellow", "corporate"] },
{ id: "revolut", name: "Revolut", category: "Fintech", keywords: ["banking", "finance", "dark", "modern"] },
{ id: "wise", name: "Wise", category: "Fintech", keywords: ["transfer", "finance", "green", "friendly"] },
// Enterprise & Consumer
{ id: "airbnb", name: "Airbnb", category: "Consumer", keywords: ["travel", "hospitality", "warm", "friendly", "coral"] },
{ id: "apple", name: "Apple", category: "Consumer", keywords: ["premium", "minimal", "luxury", "clean", "elegant", "white", "editorial"] },
{ id: "ibm", name: "IBM", category: "Enterprise", keywords: ["enterprise", "corporate", "blue", "serious"] },
{ id: "meta", name: "Meta", category: "Enterprise", keywords: ["social", "facebook", "blue", "modern", "platform"] },
{ id: "nvidia", name: "NVIDIA", category: "Enterprise", keywords: ["gpu", "gaming", "green", "dark", "tech", "futuristic"] },
{ id: "spacex", name: "SpaceX", category: "Enterprise", keywords: ["space", "engineering", "dark", "cinematic", "bold", "futuristic"] },
{ id: "spotify", name: "Spotify", category: "Consumer", keywords: ["music", "audio", "green", "dark", "vibrant", "creative"] },
{ id: "uber", name: "Uber", category: "Consumer", keywords: ["transport", "urban", "black", "clean", "modern"] },
{ id: "vodafone", name: "Vodafone", category: "Enterprise", keywords: ["telecom", "red", "speech-mark", "corporate"] },
// Retail & Lifestyle
{ id: "nike", name: "Nike", category: "Retail", keywords: ["sport", "athletic", "bold", "monochrome", "uppercase", "swoosh"] },
{ id: "playstation", name: "PlayStation", category: "Retail", keywords: ["gaming", "console", "blue", "premium", "dark", "futuristic"] },
{ id: "shopify", name: "Shopify", category: "Retail", keywords: ["commerce", "merchant", "green", "ecommerce"] },
{ id: "starbucks", name: "Starbucks", category: "Retail", keywords: ["coffee", "warm", "green", "premium", "lifestyle"] },
// Media & Editorial
{ id: "theverge", name: "The Verge", category: "Media", keywords: ["news", "editorial", "purple", "tech", "magazine"] },
{ id: "warm-editorial", name: "Warm Editorial", category: "Media", keywords: ["editorial", "warm", "literary", "serif", "magazine", "blog"] },
{ id: "wired", name: "Wired", category: "Media", keywords: ["editorial", "magazine", "bold", "tech", "futuristic"] },
// Car Brands
{ id: "bmw", name: "BMW", category: "Cars", keywords: ["luxury", "automotive", "blue", "premium", "elegant"] },
{ id: "bugatti", name: "Bugatti", category: "Cars", keywords: ["luxury", "supercar", "blue", "premium", "hypercar"] },
{ id: "ferrari", name: "Ferrari", category: "Cars", keywords: ["luxury", "speed", "red", "premium", "bold", "cinematic"] },
{ id: "lamborghini", name: "Lamborghini", category: "Cars", keywords: ["luxury", "supercar", "yellow", "bold", "aggressive"] },
{ id: "renault", name: "Renault", category: "Cars", keywords: ["automotive", "french", "yellow", "modern"] },
{ id: "tesla", name: "Tesla", category: "Cars", keywords: ["electric", "futuristic", "minimal", "dark", "clean", "tech"] },
];
/** Local disk cache directory for design system files. */
const CACHE_DIR = (0, path_1.join)(os.homedir(), ".maestro-toolbox", "design-systems");
/** In-memory cache to avoid repeated disk reads within the same session. */
const memoryCache = new Map();
/**
* Section-aware truncation for DESIGN.md files.
* DESIGN.md structure is typically: Colors → Typography → Components → Layout.
* Naive substring truncation drops half the doc — this preserves every H2
* section by allocating the char budget proportionally across them.
*/
function truncateByDesignSection(content, maxChars) {
if (content.length <= maxChars)
return content;
// Split on H2 boundaries. The lookahead keeps the `## ` header with its section.
const sections = content.split(/(?=^## )/m);
if (sections.length <= 2) {
// No meaningful H2 structure — fall back to naive truncation.
return content.substring(0, maxChars) + "\n\n[... truncated for context]";
}
// Give each section a proportional slice, keeping its header intact.
const budgetPerSection = Math.floor(maxChars / sections.length);
const pieces = sections.map((section) => {
const trimmed = section.trimEnd();
if (trimmed.length <= budgetPerSection)
return trimmed;
const body = trimmed.substring(0, Math.max(budgetPerSection - 16, 200));
return body.trimEnd() + "\n[...trimmed]";
});
return pieces.join("\n\n");
}
/** Score a design entry against a freeform intent string. Exact keyword matches win. */
function scoreAgainstIntent(entry, terms) {
if (terms.length === 0)
return 0;
const haystack = `${entry.name} ${entry.category} ${entry.keywords.join(" ")}`.toLowerCase();
let score = 0;
for (const t of terms) {
if (entry.keywords.some((k) => k === t))
score += 3;
else if (entry.name.toLowerCase() === t)
score += 3;
else if (haystack.includes(t))
score += 1;
}
return score;
}
/** Break a freeform intent into searchable terms (lowercase, dedup, >=3 chars). */
function extractIntentTerms(intent) {
const raw = intent.toLowerCase().split(/[^a-z0-9-]+/).filter((t) => t.length >= 3);
return Array.from(new Set(raw));
}
/** Read from local disk cache. */
async function readLocalCache(id) {
try {
const filePath = (0, path_1.join)(CACHE_DIR, `${id}.md`);
const content = await (0, promises_1.readFile)(filePath, "utf-8");
return content || null;
}
catch {
return null;
}
}
/** Write to local disk cache for offline access. */
async function writeLocalCache(id, content) {
try {
await (0, promises_1.mkdir)(CACHE_DIR, { recursive: true });
const filePath = (0, path_1.join)(CACHE_DIR, `${id}.md`);
await (0, promises_1.writeFile)(filePath, content, "utf-8");
}
catch {
// Silent fail — disk cache is best-effort
}
}
/**
* Fetch a DESIGN.md with 3-tier caching:
* 1. In-memory (instant, same session)
* 2. Local disk (~/.maestro-toolbox/design-systems/)
* 3. Remote GitHub (saved to disk on success)
*/
async function fetchDesignMd(id) {
// Tier 1: In-memory cache
if (memoryCache.has(id))
return memoryCache.get(id);
// Tier 2: Local disk cache (stored full-size; truncate at read time for current budget).
const localContent = await readLocalCache(id);
if (localContent) {
const trimmed = truncateByDesignSection(localContent, _maxDesignChars);
memoryCache.set(id, trimmed);
return trimmed;
}
// Tier 3: Remote fetch + save to disk
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
const url = `${REPO_RAW_BASE}/${id}/DESIGN.md`;
const response = await fetch(url, { signal: controller.signal });
clearTimeout(timeout);
if (!response.ok)
return null;
const content = await response.text();
// Persist the FULL file to disk so changing the budget later doesn't require re-fetching.
await writeLocalCache(id, content);
// Cap chars with section-aware truncation to preserve component/layout sections.
const trimmed = truncateByDesignSection(content, _maxDesignChars);
memoryCache.set(id, trimmed);
return trimmed;
}
catch {
return null;
}
}
function createDesignSystemTools() {
const listTool = (0, sdk_1.tool)({
name: "list_design_systems",
description: "List the 70 available design systems from real brands (Apple, Figma, Spotify, Nike, Tesla, etc.). " +
"Each has a full DESIGN.md with colors, typography, components, and layout rules. " +
"Pass a freeform style/mood string as `filter` (e.g. 'dark analytics dashboard', 'elegant editorial blog') " +
"to get the top matches ranked by keyword fit. Omit filter to browse everything.",
parameters: {
filter: zod_1.z.string().optional().describe("Optional style/mood description. Keywords like 'dark', 'minimal', 'editorial', 'bold', 'playful', 'premium', 'technical', 'creative' work best. Returns top matches ranked by fit."),
},
implementation: async ({ filter }) => {
if (!filter) {
return {
count: DESIGN_SYSTEMS.length,
systems: DESIGN_SYSTEMS.map(d => ({ id: d.id, name: d.name, category: d.category, style: d.keywords.join(", ") })),
};
}
const terms = extractIntentTerms(filter);
if (terms.length === 0) {
// Fallback to substring match when filter has no usable terms.
const term = filter.toLowerCase();
const results = DESIGN_SYSTEMS.filter(d => d.name.toLowerCase().includes(term) ||
d.category.toLowerCase().includes(term) ||
d.keywords.some(k => k.includes(term)));
return {
count: results.length,
systems: results.map(d => ({ id: d.id, name: d.name, category: d.category, style: d.keywords.join(", ") })),
};
}
const ranked = DESIGN_SYSTEMS
.map(entry => ({ entry, score: scoreAgainstIntent(entry, terms) }))
.filter(s => s.score > 0)
.sort((a, b) => b.score - a.score)
.slice(0, 8);
if (ranked.length === 0) {
return {
count: 0,
systems: [],
hint: "No matches. Try broader keywords: dark, minimal, editorial, bold, playful, premium, technical, creative, modern, clean.",
};
}
return {
count: ranked.length,
systems: ranked.map(s => ({
id: s.entry.id,
name: s.entry.name,
category: s.entry.category,
style: s.entry.keywords.join(", "),
})),
next_step: "Call load_design_system with the best-matching id.",
};
},
});
const loadTool = (0, sdk_1.tool)({
name: "load_design_system",
description: "Load a DESIGN.md from a real brand's design system. Returns complete design specs: " +
"colors (hex), typography (fonts, sizes), components (buttons, cards), layout rules, and more. " +
"Use the loaded specs to guide your HTML/CSS generation for consistent, professional results. " +
"Choose the design system that best matches the mood/style of the user's project.",
parameters: {
id: zod_1.z.string().describe("Design system ID (e.g. 'apple', 'figma', 'spotify'). Use list_design_systems to see all options."),
},
implementation: async ({ id }, { status }) => {
const normalized = id.toLowerCase().trim();
const entry = DESIGN_SYSTEMS.find(d => d.id === normalized);
if (!entry) {
// Fuzzy suggestion: substring match against id, name, and keywords.
const suggestions = DESIGN_SYSTEMS
.filter(d => d.id.includes(normalized) ||
d.name.toLowerCase().includes(normalized) ||
d.keywords.some(k => k.includes(normalized)))
.slice(0, 5)
.map(d => ({ id: d.id, name: d.name, category: d.category }));
return {
error: `Unknown design system '${id}'.`,
did_you_mean: suggestions.length > 0 ? suggestions : undefined,
hint: suggestions.length === 0
? "Call list_design_systems with a style/mood description as filter, or omit filter to browse everything."
: "Retry with one of the IDs in did_you_mean.",
};
}
status(`Loading ${entry.name} design system...`);
const content = await fetchDesignMd(entry.id);
if (!content) {
return { error: `Failed to fetch DESIGN.md for ${entry.name}. No local cache available and remote fetch failed. Try again when internet is available — the file will be cached locally for future offline use.` };
}
return {
id: entry.id,
name: entry.name,
category: entry.category,
design_md: content,
};
},
});
const preDownloadTool = (0, sdk_1.tool)({
name: "predownload_design_systems",
description: "Pre-download ALL 70 design system files for offline use. " +
"Run this once to cache every DESIGN.md locally at ~/.maestro-toolbox/design-systems/. " +
"After this, load_design_system works instantly without internet.",
parameters: {},
implementation: async (_args, { status }) => {
await (0, promises_1.mkdir)(CACHE_DIR, { recursive: true });
let downloaded = 0;
let skipped = 0;
let failed = 0;
for (const entry of DESIGN_SYSTEMS) {
// Skip if already cached on disk
const cached = await readLocalCache(entry.id);
if (cached) {
skipped++;
continue;
}
status(`Downloading ${entry.name} (${downloaded + skipped + failed + 1}/${DESIGN_SYSTEMS.length})...`);
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
const url = `${REPO_RAW_BASE}/${entry.id}/DESIGN.md`;
const response = await fetch(url, { signal: controller.signal });
clearTimeout(timeout);
if (!response.ok) {
failed++;
continue;
}
const content = await response.text();
// Save the FULL file to disk — truncation happens at read time based on current budget.
await writeLocalCache(entry.id, content);
memoryCache.set(entry.id, truncateByDesignSection(content, _maxDesignChars));
downloaded++;
// Small delay to avoid rate limiting
await new Promise(r => setTimeout(r, 200));
}
catch {
failed++;
}
}
return {
total: DESIGN_SYSTEMS.length,
downloaded,
already_cached: skipped,
failed,
cache_dir: CACHE_DIR,
};
},
});
return [listTool, loadTool, preDownloadTool];
}
//# sourceMappingURL=designSystems.js.map