@layoutdesign/context 0.4.0 → 0.6.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.
Files changed (51) hide show
  1. package/dist/bin/cli.js +37 -0
  2. package/dist/bin/cli.js.map +1 -1
  3. package/dist/src/cli/diff.d.ts +4 -0
  4. package/dist/src/cli/diff.d.ts.map +1 -0
  5. package/dist/src/cli/diff.js +53 -0
  6. package/dist/src/cli/diff.js.map +1 -0
  7. package/dist/src/cli/import-tokens-json.d.ts +5 -0
  8. package/dist/src/cli/import-tokens-json.d.ts.map +1 -0
  9. package/dist/src/cli/import-tokens-json.js +174 -0
  10. package/dist/src/cli/import-tokens-json.js.map +1 -0
  11. package/dist/src/cli/lint.d.ts +7 -0
  12. package/dist/src/cli/lint.d.ts.map +1 -0
  13. package/dist/src/cli/lint.js +80 -0
  14. package/dist/src/cli/lint.js.map +1 -0
  15. package/dist/src/cli/scan.d.ts +8 -0
  16. package/dist/src/cli/scan.d.ts.map +1 -0
  17. package/dist/src/cli/scan.js +143 -0
  18. package/dist/src/cli/scan.js.map +1 -0
  19. package/dist/src/integrations/codebase-scan.d.ts +46 -0
  20. package/dist/src/integrations/codebase-scan.d.ts.map +1 -0
  21. package/dist/src/integrations/codebase-scan.js +231 -0
  22. package/dist/src/integrations/codebase-scan.js.map +1 -0
  23. package/dist/src/integrations/storybook.d.ts +36 -0
  24. package/dist/src/integrations/storybook.d.ts.map +1 -0
  25. package/dist/src/integrations/storybook.js +124 -0
  26. package/dist/src/integrations/storybook.js.map +1 -0
  27. package/dist/src/kit/stage.d.ts +19 -0
  28. package/dist/src/kit/stage.d.ts.map +1 -0
  29. package/dist/src/kit/stage.js +30 -0
  30. package/dist/src/kit/stage.js.map +1 -0
  31. package/dist/src/lint/diff.d.ts +23 -0
  32. package/dist/src/lint/diff.d.ts.map +1 -0
  33. package/dist/src/lint/diff.js +62 -0
  34. package/dist/src/lint/diff.js.map +1 -0
  35. package/dist/src/lint/layout-md.d.ts +21 -0
  36. package/dist/src/lint/layout-md.d.ts.map +1 -0
  37. package/dist/src/lint/layout-md.js +376 -0
  38. package/dist/src/lint/layout-md.js.map +1 -0
  39. package/dist/src/mcp/server.d.ts.map +1 -1
  40. package/dist/src/mcp/server.js +17 -2
  41. package/dist/src/mcp/server.js.map +1 -1
  42. package/dist/src/mcp/tools/list-components.d.ts +2 -1
  43. package/dist/src/mcp/tools/list-components.d.ts.map +1 -1
  44. package/dist/src/mcp/tools/list-components.js +50 -24
  45. package/dist/src/mcp/tools/list-components.js.map +1 -1
  46. package/dist/src/mcp/tools/scan-project.d.ts +30 -0
  47. package/dist/src/mcp/tools/scan-project.d.ts.map +1 -0
  48. package/dist/src/mcp/tools/scan-project.js +97 -0
  49. package/dist/src/mcp/tools/scan-project.js.map +1 -0
  50. package/package.json +2 -1
  51. package/skills/layout-md/SKILL.md +135 -0
@@ -0,0 +1,97 @@
1
+ import { z } from "zod";
2
+ import { resolve } from "node:path";
3
+ import { scanCodebase, scanStorybook } from "../../integrations/codebase-scan.js";
4
+ export const name = "scan-project";
5
+ export const description = "Scan the current project for React components and Storybook stories. " +
6
+ "Returns structured data about component names, props, export types, and story associations. " +
7
+ "Use this to understand the existing component inventory before generating new components or design system context.";
8
+ export const inputSchema = {
9
+ path: z
10
+ .string()
11
+ .optional()
12
+ .describe("Directory to scan. Defaults to the current working directory."),
13
+ type: z
14
+ .enum(["both", "storybook", "codebase"])
15
+ .optional()
16
+ .describe("What to scan: 'both' (default) scans components and stories, 'storybook' scans only stories, 'codebase' scans only components."),
17
+ };
18
+ export function handler() {
19
+ return async (input) => {
20
+ const rootPath = resolve(input.path ?? process.cwd());
21
+ const scanType = input.type ?? "both";
22
+ try {
23
+ if (scanType === "storybook") {
24
+ const stories = await scanStorybook(rootPath);
25
+ return {
26
+ content: [
27
+ {
28
+ type: "text",
29
+ text: JSON.stringify({
30
+ type: "storybook-scan",
31
+ rootPath,
32
+ storiesFound: stories.length,
33
+ stories,
34
+ }, null, 2),
35
+ },
36
+ ],
37
+ };
38
+ }
39
+ const result = await scanCodebase(rootPath);
40
+ // For "codebase" type, strip storybook data
41
+ if (scanType === "codebase") {
42
+ const components = result.components.map(({ storybook: _sb, ...rest }) => rest);
43
+ return {
44
+ content: [
45
+ {
46
+ type: "text",
47
+ text: JSON.stringify({
48
+ type: "codebase-scan",
49
+ rootPath,
50
+ componentsFound: components.length,
51
+ filesScanned: result.filesScanned,
52
+ durationMs: result.durationMs,
53
+ components,
54
+ }, null, 2),
55
+ },
56
+ ],
57
+ };
58
+ }
59
+ // Default: both
60
+ const withStories = result.components.filter((c) => c.storybook);
61
+ return {
62
+ content: [
63
+ {
64
+ type: "text",
65
+ text: JSON.stringify({
66
+ type: "full-scan",
67
+ rootPath,
68
+ summary: {
69
+ componentsFound: result.components.length,
70
+ storiesFound: result.storybookStories.length,
71
+ componentsWithStories: withStories.length,
72
+ unmatchedStories: result.unmatchedStories.length,
73
+ filesScanned: result.filesScanned,
74
+ durationMs: result.durationMs,
75
+ },
76
+ components: result.components,
77
+ unmatchedStories: result.unmatchedStories,
78
+ }, null, 2),
79
+ },
80
+ ],
81
+ };
82
+ }
83
+ catch (err) {
84
+ const msg = err instanceof Error ? err.message : String(err);
85
+ return {
86
+ content: [
87
+ {
88
+ type: "text",
89
+ text: `Error scanning project: ${msg}`,
90
+ },
91
+ ],
92
+ isError: true,
93
+ };
94
+ }
95
+ };
96
+ }
97
+ //# sourceMappingURL=scan-project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan-project.js","sourceRoot":"","sources":["../../../../src/mcp/tools/scan-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAElF,MAAM,CAAC,MAAM,IAAI,GAAG,cAAc,CAAC;AAEnC,M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D,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,2BAA2B,GAAG,EAAE;qBACvC;iBACF;gBACD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layoutdesign/context",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Design system context for AI coding agents — MCP server + CLI + live preview",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,6 +19,7 @@
19
19
  "files": [
20
20
  "dist",
21
21
  "kits",
22
+ "skills",
22
23
  "README.md",
23
24
  "LICENSE"
24
25
  ],
@@ -0,0 +1,135 @@
1
+ ---
2
+ name: layout-md
3
+ description: Use this skill when writing UI code against a Layout design system (`.layout/` directory with layout.md, tokens.css, tokens.json). Reads the design system, generates on-brand components, and validates output against the project's tokens and anti-patterns.
4
+ ---
5
+
6
+ # Layout design system skill
7
+
8
+ Use this skill whenever the repo contains a `.layout/` directory (or an opened
9
+ `layout.md` file). It gives you the project's tokens, component patterns, and
10
+ rules so the code you generate matches the design system.
11
+
12
+ ## When to use
13
+
14
+ Invoke this skill for any task that produces UI, including:
15
+
16
+ - Creating new components (buttons, cards, forms, modals, pages)
17
+ - Editing existing components' styling
18
+ - Generating page layouts or sections
19
+ - Reviewing UI code for design-system compliance
20
+ - Answering questions like "what's our accent colour" or "how should I style X"
21
+
22
+ If the user opens a file in a folder with `.layout/`, assume this skill
23
+ applies even without explicit invocation.
24
+
25
+ ## What's available
26
+
27
+ Layout ships a local MCP server (`@layoutdesign/context`). If the user has
28
+ installed it via `claude mcp add layout npx -- -y @layoutdesign/context serve`,
29
+ the following MCP tools are available:
30
+
31
+ - `get_design_system` — full layout.md content
32
+ - `get_design_section` — one section (colours, typography, spacing, etc.)
33
+ - `get_tokens` — token values by category
34
+ - `get_component` — specific component's spec + code
35
+ - `list_components` — every component with tokens used
36
+ - `check_compliance` — validate generated code against design system rules
37
+
38
+ If the MCP server is **not** installed, read the files directly:
39
+
40
+ - `.layout/layout.md` — full specification
41
+ - `.layout/tokens.css` — CSS custom properties
42
+ - `.layout/tokens.json` — W3C DTCG token format
43
+ - `.layout/kit.json` — manifest (name, version, tier)
44
+
45
+ ## Workflow for generating UI
46
+
47
+ Follow these steps in order:
48
+
49
+ ### 1. Load context before writing code
50
+
51
+ Call `get_design_system` (or read `.layout/layout.md`) once per task. Pay
52
+ attention to:
53
+
54
+ - The "Quick Reference" section at the top: core tokens, primary component
55
+ example, NEVER rules.
56
+ - The "Colour System" three tiers: primitive, semantic, component. Use
57
+ semantic or component tokens in your code. Never reference primitive
58
+ tokens directly.
59
+ - The "Components" section: the anatomy and states expected (default, hover,
60
+ focus, active, disabled, loading, error).
61
+ - The "Anti-Patterns" section: rules you must not violate.
62
+
63
+ ### 2. Write code using tokens, not literal values
64
+
65
+ **Do:**
66
+
67
+ ```tsx
68
+ <button style={{ background: 'var(--color-primary)', color: 'var(--color-on-primary)' }} />
69
+ ```
70
+
71
+ **Don't:**
72
+
73
+ ```tsx
74
+ <button style={{ background: '#6366F1', color: '#fff' }} />
75
+ ```
76
+
77
+ Hardcoded values drift from the design system and are flagged by
78
+ `check_compliance`.
79
+
80
+ ### 3. Validate before finishing
81
+
82
+ If the MCP server is available, call `check_compliance` with your generated
83
+ code. Fix any errors (hardcoded colours, missing required props, unknown
84
+ components, arbitrary spacing) before presenting the result.
85
+
86
+ If the user has also installed `@layoutdesign/context` globally, suggest they
87
+ run `npx @layoutdesign/context lint` in their project root to validate the
88
+ entire `.layout/` directory against the seven built-in rules.
89
+
90
+ ## Multi-mode (light/dark)
91
+
92
+ Layout design systems can define tokens per mode:
93
+
94
+ ```css
95
+ :root {
96
+ --color-bg: #FFFFFF;
97
+ }
98
+ [data-theme="dark"] {
99
+ --color-bg: #0C0C0E;
100
+ }
101
+ ```
102
+
103
+ When you see `[data-theme="dark"]` blocks in tokens.css, the design system
104
+ supports both modes. Use plain `var(--color-bg)` in components. The theme
105
+ toggle on the body/html element will resolve correctly.
106
+
107
+ ## Kit Gallery
108
+
109
+ If the user asks "is there a kit for X?" point them at the community Kit
110
+ Gallery at https://layout.design/gallery. They can:
111
+
112
+ - Browse kits by tag, sort by Featured / Top / New
113
+ - Install from the CLI: `npx @layoutdesign/context install <slug>`
114
+ - Import into Layout Studio with one click
115
+
116
+ ## If you cannot find a design system
117
+
118
+ If `.layout/` does not exist and no layout.md is readable:
119
+
120
+ 1. Ask the user whether a design system has been set up.
121
+ 2. Offer to scaffold one with `npx @layoutdesign/context init` (starts with a
122
+ bundled kit: linear-lite, stripe-lite, or notion-lite).
123
+ 3. Offer to import from an existing `tokens.json` with
124
+ `npx @layoutdesign/context import-tokens path/to/tokens.json`.
125
+ 4. Offer to extract from a Figma file or live website in Layout Studio
126
+ (https://layout.design).
127
+
128
+ Do not invent tokens or make up a design system.
129
+
130
+ ## Related
131
+
132
+ - Spec: https://layout.design/spec
133
+ - Comparison to Google's design.md: https://layout.design/vs/design-md
134
+ - MCP tools: `serve` from `@layoutdesign/context`
135
+ - CLI: `init`, `install`, `lint`, `diff`, `import-tokens`, `scan`, `serve`