agentleFS
MongoDBKnown publishermongodb/leafygreen-ui/.github/copilot-instructions.md

leafygreen-ui

Copilot instructions273 starsChanged 7 months agoApache-2.0View on GitHub

This document provides comprehensive guidance for coding agents working on the LeafyGreen UI design system repository. Following these instructions will minimize build failures, validation errors, and rejected pull requests. LeafyGreen UI is MongoDB's React component library and design system consisting of: Refer to package.json for the required Node and pnpm versions. MUST use pnpm, not npm or yarn Follow this workflow for all development tasks: Each package supports these scripts (defined in individual package.json): The CI/CD system runs validations on…

The file

We split this copilot-instructions.md into the rules it gives an agent

10 rules. About 0 are common, 6 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    MUST use pnpm, not npm or yarn

    line 32
  2. Distinctive:

    Follow this workflow for all development tasks:

    line 36
  3. Distinctive:

    ALWAYS run this before any development work

    line 44
  4. Very specific:

    Add/update tests in .spec.tsx files

    line 49
  5. Very specific:

    Update stories in .stories.tsx files

    line 50
  6. Very specific:

    CRITICAL: Always use pnpm run fix instead of manual formatting fixes

    line 79
  7. Distinctive:

    All checks must pass in CI

    line 83
  8. Distinctive:

    Update documentation as needed

    line 85
  9. Distinctive:

    Test setup with Jest/React Testing Library

    line 122
  10. Very specific:

    Use workspace:^ for internal dependencies (Example: "@leafygreen-ui/palette": "workspace:^")

    line 148

≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

LeafyGreen UI - Copilot Instructions

This document provides comprehensive guidance for coding agents working on the LeafyGreen UI design system repository. Following these instructions will minimize build failures, validation errors, and rejected pull requests.

Repository Overview

LeafyGreen UI is MongoDB's React component library and design system consisting of:

  • 100+ workspace packages across 5 scopes: @leafygreen-ui, @lg-charts, @lg-chat, @lg-mcp, and @lg-tools
  • Languages/Frameworks: TypeScript, React 18, Emotion (CSS-in-JS), Storybook
  • Build System: Turbo monorepo with pnpm workspaces

Project Structure

leafygreen-ui/
├── packages/        # @leafygreen-ui core components (button, modal, etc.)
├── charts/          # @lg-charts data visualization components
├── chat/            # @lg-chat conversational UI components
├── mcp/             # @lg-mcp MCP (Model Context Protocol) components and hooks
├── tools/           # @lg-tools build system, CLI, linting, etc.
├── stories/         # Storybook files unrelated to a specific component
└── scripts/         # Repository maintenance scripts

Build System & Development Commands

Required Environment

Refer to package.json for the required Node and pnpm versions.

MUST use pnpm, not npm or yarn

Development Workflow & Commands

Follow this workflow for all development tasks:

  1. Initial Setup (required after clone or when switching branches):

    pnpm run init  # Installs dependencies and builds all packages
    • ALWAYS run this before any development work
  2. Making Changes:

    • Edit component files in src/
    • Add/update tests in .spec.tsx files
    • Update stories in .stories.tsx files
  3. Development Commands:

    # Build all packages (uses Turbo, typically 6-10 seconds with cache)
    pnpm build
    
    # Start Storybook for development
    pnpm start          # Starts on port 9001
    
    # Run tests
    pnpm test                              # All tests
    pnpm run test --filter="@leafygreen-ui/*"  # Specific scope
    
    # Linting
    pnpm lint           # Check only
    pnpm run fix        # Auto-fix issues
  4. Before Committing:

    pnpm build          # Ensure builds pass
    pnpm lint           # Check for issues
    pnpm test           # Run test suite
    pnpm changeset      # Document changes for release
    • CRITICAL: Always use pnpm run fix instead of manual formatting fixes
    • Runs ESLint, Prettier, and npmPkgJsonLint
  5. PR Submission:
    • All checks must pass in CI
    • Include meaningful test coverage
    • Update documentation as needed

Package-Level Commands

Each package supports these scripts (defined in individual package.json):

{
  "scripts": {
    "build": "lg-build bundle",
    "tsc": "lg-build tsc",
    "docs": "lg-build docs"
  }
}

Validation Pipeline

The CI/CD system runs validations on every PR

For regular PRs, refer to .github/workflows/pr.yml

PR Requirements

Refer to .github/pull_request_template.md for PR requirements

Package Development Guidelines

Creating New Components

pnpm create-package my-new-component

This scaffolds:

  • Package structure with TypeScript configs
  • Test setup with Jest/React Testing Library
  • Storybook stories
  • Build configuration

Package Structure

Each package follows this structure:

packages/component-name/
├── src/
│   ├── Component/
│   │   ├── Component.tsx
│   │   ├── Component.styles.ts
│   │   ├── Component.spec.tsx
│   │   └── index.ts
│   ├── Component.stories.tsx
│   ├── index.ts
│   └── types.ts
├── package.json
├── README.md
└── CHANGELOG.md

Workspace Dependencies

  • Use workspace:^ for internal dependencies (Example: "@leafygreen-ui/palette": "workspace:^")
  • External dependencies use specific versions with caret ^ version notation.
  • External dependencies in @lg-tools/* packages use explicit dependency versions (with no caret ^ or tilde ~)

TypeScript Configuration

  • Extends @lg-tools/build/config/package.tsconfig.json
  • Path mapping configured in root tsconfig.json:
    {
      "paths": {
        "@leafygreen-ui/*": ["packages/*/src"],
        "@lg-charts/*": ["charts/*/src"],
        "@lg-chat/*": ["chat/*/src"],
        "@lg-tools/*": ["tools/*/src"]
      }
    }

File Locations & Configurations

Key Configuration Files

  • eslint.config.mjs - Linting rules (extends @lg-tools/lint)
  • prettier.config.js - Code formatting (extends @lg-tools/lint)
  • turbo.json - Build orchestration
  • tsconfig.json - TypeScript path mapping and compilation
  • .github/workflows/ - CI/CD pipeline definitions

Build Tools

  • Main CLI: @lg-tools/cli provides lg command
  • Build System: @lg-tools/build provides lg-build commands
  • Validation: @lg-tools/validate checks dependencies and structure
  • Testing: @lg-tools/test provides Jest configuration

Performance Notes

  • Build caching: Turbo extensively caches builds - clean cache if issues arise
  • Icon package: Has special build caching due to SVG generation complexity
  • Storybook: Large application - expect 30+ second build times

Code Style guide

Refer to STYLEGUIDE.md for code style guidelines

Additional instructions

  • For Storybook files **/*.stories.ts, do not comment on the inclusion of console logs.

Trust These Instructions

These instructions are based on comprehensive exploration and testing of the actual codebase. Only search for additional information if:

  • These instructions are incomplete for your specific task
  • You encounter errors not covered in the troubleshooting section
  • The codebase has changed since these instructions were created

Always prefer following these established patterns over creating new approaches.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.