Skip to content

xinetzone/SpecWeave / .agents/skills/design-library-creator

design-library-creator

Flagged

Create, expand, and refine professional Design Libraries / Design Systems with structured token architecture. ONLY invoke when user EXPLICITLY mentions design-system terminology: 'Design Library', 'Design System', '设计系统', '设计库', 'token system', 'design tokens', '组件库规范', or provides a parsed design-spec bundle (ZIP/Figma export). Also covers creating a new theme / color theme as a design-system deliverable (创建主题/新建暖色主题/深色主题等 — tokens + palette + component styling). Do NOT route here for: '素材库', '全套素材', '素材合集', '物料库', '生成素材', '做一套设计', '做几张图', '设计一套页面', '帮我出图', page/poster/landing-page creation, or any visual-asset generation intent where the user does not demonstrate knowledge of design-system concepts. Those belong to solo-design.

FileKindSize
SKILL.mdskill md19.3 KB
aesthetics/dark-mode.mdmarkdown1.8 KB
aesthetics/index.mdmarkdown33.8 KB
aesthetics/navigation-footer.mdmarkdown2.2 KB
aesthetics/screen-craft.mdmarkdown9.2 KB
aesthetics/self-check.mdmarkdown24.9 KB
examples/templates/component-dispatch-rules.mdmarkdown9.1 KB
examples/templates/figma-token-gen.mdmarkdown50.3 KB
examples/templates/incremental.mdmarkdown5.7 KB
examples/templates/phase-2-analysts.mdmarkdown6.8 KB
examples/templates/phase-2-structured-spec.mdmarkdown8.8 KB
examples/templates/phase-2.5-intent-synthesis.mdmarkdown31.0 KB
examples/templates/phase-3-4-component.mdmarkdown9.0 KB
examples/templates/phase-4-ui-kit.mdmarkdown39.3 KB
examples/templates/phase-5-docs.mdmarkdown12.5 KB
examples/templates/scratch-token-gen.mdmarkdown14.4 KB
examples/templates/specimen-reference.htmlother6.0 KB
file-specs/css-json.mdmarkdown9.5 KB
file-specs/css-tokens.mdmarkdown33.6 KB
file-specs/design-library-output.mdmarkdown10.3 KB
file-specs/design-spec-bundle.mdmarkdown5.9 KB
file-specs/documentation.mdmarkdown12.3 KB
file-specs/preview-pages.mdmarkdown28.0 KB
file-specs/ui-kit.mdmarkdown28.5 KB
operation-policies/agent-orchestration.mdmarkdown20.2 KB
operation-policies/bundle-exploration.mdmarkdown9.0 KB
operation-policies/decision-rules.mdmarkdown10.7 KB
operation-policies/quality-gates.mdmarkdown10.5 KB
operation-policies/user-output-policy.mdmarkdown7.8 KB
scripts/check-design-library-phase.mjsscript85.1 KB
scripts/copy-bundle-assets.mjsscript12.3 KB
scripts/css-to-json.mjsscript53.1 KB
scripts/css-utils.mjsscript748 B
scripts/extract-components-css.mjsscript10.3 KB
scripts/generate-uikit-plan.mjsscript27.5 KB
scripts/jsonl-utils.mjsscript7.3 KB
scripts/validate-design-library-output.mjsscript3.1 KB
scripts/validate-intent.mjsscript7.3 KB
scripts/validate-token-input.mjsscript4.0 KB
scripts/validate-uikit-plan.mjsscript13.6 KB
skill-release-manifest.jsonconfig202 B
workflows/create-from-scratch.mdmarkdown22.5 KB
workflows/create-from-structured-spec.mdmarkdown17.5 KB
workflows/create-library.mdmarkdown53.0 KB
workflows/expand-components.mdmarkdown9.0 KB
workflows/generate-additional-kit.mdmarkdown4.9 KB
workflows/refine-library.mdmarkdown9.7 KB

scripts/copy-bundle-assets.mjs

View on GitHub
#!/usr/bin/env node

import fs from 'node:fs';
import path from 'node:path';
import { readDataFile, resolveDataPath } from './jsonl-utils.mjs';

function parseArgs(argv) {
  const args = {
    bundle: undefined,
    output: undefined,
    tmp: undefined,
    manifest: undefined,
    splitComponents: undefined,
  };

  for (let i = 0; i < argv.length; i += 1) {
    const arg = argv[i];
    if (arg === '--bundle') {
      args.bundle = argv[i + 1];
      i += 1;
    } else if (arg === '--output') {
      args.output = argv[i + 1];
      i += 1;
    } else if (arg === '--tmp') {
      args.tmp = argv[i + 1];
      i += 1;
    } else if (arg === '--manifest') {
      args.manifest = argv[i + 1];
      i += 1;
    } else if (arg === '--split-components') {
      args.splitComponents = argv[i + 1];
      i += 1;
    }
  }

  return args;
}

function ensureDir(dirPath) {
  if (!fs.existsSync(dirPath)) {
    fs.mkdirSync(dirPath, { recursive: true });
  }
}

function copyFile(src, dest, errors) {
  try {
    if (!fs.existsSync(src)) {
      errors.push(`skip: source not found: ${src}`);
      return false;
    }
    ensureDir(path.dirname(dest));
    fs.copyFileSync(src, dest);
    return true;
  } catch (err) {
    errors.push(`copy failed: ${src} -> ${dest}: ${err.message}`);
    return false;
  }
}

function copyOptionalFile(src, dest, warnings) {
  try {
    if (!fs.existsSync(src)) {
      warnings.push(`optional source not found: ${src}`);
      return false;
    }
    ensureDir(path.dirname(dest));
    fs.copyFileSync(src, dest);
    return true;
  } catch (err) {
    warnings.push(`optional copy failed: ${src} -> ${dest}: ${err.message}`);
    return false;
  }
}

/** 检测不可升级的 v1 证据(semanticTypeCandidates 系旧格式,无 identity/renderFacts) */
function isLegacyV1Evidence(data) {
  if (!data || typeof data !== 'object') return false;
  if (data.renderFacts || data.identity) return false;
  return Array.isArray(data.semanticTypeCandidates) || (Number(data.schemaVersion) === 1 && data.representativeVariants);
}

function normalizeToV6(data) {
  if (!data || typeof data !== 'object') return data;
  // Already v6
  if (data.contractKind === 'llm-render-facts' && data.renderFacts && data.schemaVersion >= 6) return data;
  // Old flat format: has identity at top level but no renderFacts wrapper
  if (data.identity && data.consumptionOrder && !data.renderFacts) {
    const { slug, name, componentClass, intentKind, identity, consumptionOrder, controlMatrix, geometry, patterns, contentPolicy, renderObligations, iconSlots, icons, sourceRefs, unknowns, riskNotes, ...rest } = data;
    return {
      schemaVersion: 6,
      contractKind: 'llm-render-facts',
      slug,
      name,
      componentClass,
      renderFacts: {
        intentKind: intentKind ?? identity?.normalizedKind ?? 'component',
        identity: identity ?? { sourceName: name, normalizedKind: 'component', rule: 'source-identity-is-authoritative' },
        consumptionOrder: consumptionOrder ?? ['identity', 'controlMatrix', 'patterns', 'geometry', 'contentPolicy', 'renderObligations', 'iconSlots', 'unknowns'],
        controlMatrix: controlMatrix ?? {},
        geometry: geometry ?? { hasEffects: false, forbiddenCss: ['invented-local-css-vars'] },
        patterns: patterns ?? {},
        contentPolicy: contentPolicy ?? { copySource: 'unknown', allowedModes: ['empty-structure'], forbiddenModes: ['skeleton-bars', 'invented-product-data'] },
        renderObligations: renderObligations ?? [],
        iconSlots: iconSlots ?? [],
        icons: icons ?? { bundle: [], lucide: [], unknownFallback: 'circle-help' },
        sourceRefs: sourceRefs ?? [],
        unknowns: unknowns ?? [],
        riskNotes: riskNotes ?? [],
      },
    };
  }
  return data;
}

function main() {
  const args = parseArgs(process.argv.slice(2));

  if (!args.bundle || !args.output || !args.tmp || !args.manifest) {
    console.error('Usage: copy-bundle-assets.mjs --bundle <path> --output <path> --tmp <path> --manifest <path> [--split-components <path>]');
    process.exit(1);
  }

  const bundleDir = path.resolve(args.bundle);
  const outputDir = path.resolve(args.output);
  const tmpDir = path.resolve(args.tmp);
  const manifestPath = path.resolve(args.manifest);

  // Read manifest (supports .jsonl and .json)
  const resolvedManifest = resolveDataPath(manifestPath);
  if (!fs.existsSync(resolvedManifest)) {
    console.error(`Critical: manifest not found: ${resolvedManifest}`);
    process.exit(1);
  }

  let manifest;
  try {
    manifest = readDataFile(resolvedManifest);
  } catch (err) {
    console.error(`Critical: failed to parse manifest: ${err.message}`);
    process.exit(1);
  }

  const errors = [];
  const warnings = [];
  let copiedFiles = 0;
  let iconsCopied = 0;
  let evidenceCopied = 0;
  let evidenceConverted = 0;
  let previewAssetsCopied = 0;
  const iconNames = [];

  // Ensure output and tmp directories exist
  ensureDir(outputDir);
  ensureDir(tmpDir);

  // Copy structural files only.
  // NOTE: Does NOT copy token files (colors_and_type.css, css.json).
  // Those are LLM-generated at runtime. See workflows/create-library.md § 2.3b.
  const splitComponentsDir = args.splitComponents ? path.resolve(args.splitComponents) : undefined;
  const componentsDir = splitComponentsDir && (fs.existsSync(path.join(splitComponentsDir, 'index.jsonl')) || fs.existsSync(path.join(splitComponentsDir, 'index.json')))
    ? splitComponentsDir
    : path.join(bundleDir, 'generated', 'components');
  const usingSplitComponents = componentsDir === splitComponentsDir;

  // Copy component evidence files to output/components/_evidence/.
  // Bundle now outputs compact evidence directly at generated/components/{slug}.jsonl
  // (no longer in a _evidence/ subfolder). DL Creator maps them to _evidence/ for
  // Phase 3 merged component synthesis to refine into output/components/{slug}.json.
  const copiedEvidenceDestNames = new Set();
  const componentIndexPath = resolveDataPath(path.join(componentsDir, 'index.json'));
  // 组件 index 复制:改写 index 内的 evidenceFile/fullJsonFile 为 _evidence/ 实际路径
  // (bundle 内是 generated/components/{slug}.jsonl 相对路径,原样透传会使 uikit-plan 指向不存在文件)。
  // Token-Only bundle 没有组件目录属正常情况,缺失走 warnings 而非 errors。
  if (!fs.existsSync(componentIndexPath)) {
    warnings.push(`optional source not found: ${componentIndexPath} (Token-Only bundle or no components)`);
  } else {
    try {
      const indexData = readDataFile(componentIndexPath);
      if (indexData && Array.isArray(indexData.components)) {
        for (const component of indexData.components) {
          if (component && typeof component.slug === 'string') {
            const evidenceRel = `components/_evidence/${component.slug}.json`;
            if (typeof component.evidenceFile === 'string') component.evidenceFile = evidenceRel;
            if (typeof component.fullJsonFile === 'string') component.fullJsonFile = evidenceRel;
          }
        }
      }
      const indexDest = path.join(outputDir, 'components', '_evidence', 'index.json');
      ensureDir(path.dirname(indexDest));
      fs.writeFileSync(indexDest, `${JSON.stringify(indexData, null, 2)}\n`, 'utf8');
      copiedFiles += 1;
      evidenceCopied += 1;
      evidenceConverted += 1;
      copiedEvidenceDestNames.add('index.json');
    } catch (err) {
      errors.push(`data copy failed: ${componentIndexPath}: ${err.message}`);
    }
  }

  if (fs.existsSync(componentsDir)) {
    try {
      const entries = fs.readdirSync(componentsDir);
      for (const entry of entries) {
        if ((entry.endsWith('.jsonl') || entry.endsWith('.json')) && entry !== 'index.jsonl' && entry !== 'index.json') {
          const srcPath = path.join(componentsDir, entry);
          if (!fs.statSync(srcPath).isFile()) continue;
          const destName = entry.replace(/\.jsonl?$/, '.json');
          if (copiedEvidenceDestNames.has(destName)) continue;
          const destPath = path.join(outputDir, 'components', '_evidence', destName);
          try {
            if (!fs.existsSync(srcPath)) {
              errors.push(`skip: source not found: ${srcPath}`);
              continue;
            }
            // Before writing evidence file, normalize to v6
            const rawData = readDataFile(srcPath);
            // 不可升级的 v1 旧格式证据:不放入 _evidence/(避免 Phase 3 子 Agent 集体 FATAL:invalid-evidence-contract),
            // 报 error 提示工作流降级到 manifest.shortlist fallback
            if (destName !== 'index.json' && isLegacyV1Evidence(rawData)) {
              errors.push(`legacy-v1-evidence: ${srcPath} uses unsupported schemaVersion=1 format; excluded from _evidence/. Re-export the bundle with a newer parser, or fall back to manifest.shortlist component synthesis.`);
              continue;
            }
            const normalizedData = destName !== 'index.json' ? normalizeToV6(rawData) : rawData;
            ensureDir(path.dirname(destPath));
            fs.writeFileSync(destPath, `${JSON.stringify(normalizedData, null, 2)}\n`, 'utf8');
            copiedFiles += 1;
            evidenceCopied += 1;
            evidenceConverted += 1;
            copiedEvidenceDestNames.add(destName);
          } catch (err) {
            errors.push(`data copy failed: ${srcPath} -> ${destPath}: ${err.message}`);
          }
        }
      }
    } catch (err) {
      errors.push(`failed to read components dir: ${err.message}`);
    }
  }

  const planningInputPath = resolveDataPath(path.join(bundleDir, 'generated', 'uikit-planning-input.json'));
  const planningDestName = path.basename(planningInputPath);
  if (copyOptionalFile(planningInputPath, path.join(tmpDir, planningDestName), warnings)) {
    copiedFiles += 1;
  }

  const visualPreviewPath = path.join(bundleDir, 'context', 'visual-preview.md');
  if (copyOptionalFile(visualPreviewPath, path.join(outputDir, 'context', 'visual-preview.md'), warnings)) {
    copiedFiles += 1;
  }

  const bundlePreviewDir = path.join(bundleDir, 'assets', 'previews');
  if (fs.existsSync(bundlePreviewDir)) {
    try {
      const entries = fs.readdirSync(bundlePreviewDir);
      for (const entry of entries) {
        const srcPath = path.join(bundlePreviewDir, entry);
        if (!fs.statSync(srcPath).isFile()) continue;
        const destPath = path.join(outputDir, 'assets', 'previews', entry);
        if (copyFile(srcPath, destPath, errors)) {
          copiedFiles += 1;
          previewAssetsCopied += 1;
        }
      }
    } catch (err) {
      errors.push(`failed to read preview assets dir: ${err.message}`);
    }
  }

  // Copy icon SVGs conditionally
  const iconsDir = path.join(bundleDir, 'assets', 'icons');
  if (fs.existsSync(iconsDir)) {
    let allSvgs;
    try {
      allSvgs = fs.readdirSync(iconsDir).filter((f) => f.endsWith('.svg'));
    } catch (err) {
      allSvgs = [];
      errors.push(`failed to read icons dir: ${err.message}`);
    }

    if (allSvgs.length > 0) {
      // Determine which icons to copy
      const availableIcons = manifest.assetAvailability?.availableIcons;
      let iconsToCopy;

      if (Array.isArray(availableIcons) && availableIcons.length > 0) {
        // Only copy icons listed in manifest
        iconsToCopy = availableIcons
          .map((name) => (name.endsWith('.svg') ? name : `${name}.svg`))
          .filter((fileName) => allSvgs.includes(fileName));
      } else {
        // Copy all SVGs
        iconsToCopy = allSvgs;
      }

      if (iconsToCopy.length > 0) {
        const outputIconsDir = path.join(outputDir, 'assets', 'icons');
        ensureDir(outputIconsDir);

        for (const fileName of iconsToCopy) {
          const srcPath = path.join(iconsDir, fileName);
          const destPath = path.join(outputIconsDir, fileName);
          if (copyFile(srcPath, destPath, errors)) {
            copiedFiles += 1;
            iconsCopied += 1;
            iconNames.push(path.basename(fileName, '.svg'));
          }
        }
      }
    }
  }

  // Output result as JSON
  const result = {
    copiedFiles,
    iconsCopied,
    evidenceCopied,
    evidenceConverted,
    evidenceContract: 'json',
    evidenceSourceDir: path.relative(bundleDir, componentsDir) || 'generated/components',
    previewAssetsCopied,
    iconNames,
    usingSplitComponents,
    warnings,
    errors,
  };

  console.log(JSON.stringify(result, undefined, 2));
  process.exit(errors.length > 0 ? 1 : 0);
}

main();
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 197kUpdated Claude CodeCodexVerifiedInstall