Skip to content

feat(llm.txt): adds script to compile llm.txt #8093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

brookton
Copy link

Add LLM.txt file generation script

Addresses open discussions:

Requirements

The script must:

  • compile mdx
  • extract all demos
  • combine with props tables and styles api data
  • include all faq content from help.mantine.dev

Notes:

  • can be added to pipelines and auto generate or update as new changes are made
  • a frontend doc about llm txt stuff similar to chakra-ui's llm docs might be worth considering as well

@rtivital
Copy link
Member

Does not work:

  • No demos code
  • No props descriptions
  • No Styles API data
### accordion
File: apps/mantine.dev/src/pages/core/accordion.mdx

export default Layout(MDX_DATA.Accordion);

## Usage

Accordion allows users to expand and collapse sections of content.
It helps manage large amounts of information in a limited space
by showing only the section headers initially and revealing content on interaction.

Accordion is commonly used for:

* FAQ sections: displaying questions as headers with answers revealed on click
* Forms: organizing long forms into sections, for example, personal info, shipping, and payment
* Menus: nested navigation in sidebars or mobile views

\[DEMO: AccordionDemos.configurator]

## Change chevron

Use the `chevron` prop to change the chevron icon. When `chevron` is set,
`chevronIconSize` prop is ignored. To remove the chevron icon, use `chevron={null}`.

To customize chevron styles, use [Styles API](/styles/styles-api/) with
[data-rotate](/styles/data-attributes/) attribute. It is set when the item
is opened if the `disableChevronRotation` prop is not set.

Example of a custom chevron icon with rotation styles:

\[DEMO: AccordionDemos.chevron]

@brookton
Copy link
Author

Does not work:

  • No demos code
  • No props descriptions
  • No Styles API data
### accordion
File: apps/mantine.dev/src/pages/core/accordion.mdx

export default Layout(MDX_DATA.Accordion);

## Usage

Accordion allows users to expand and collapse sections of content.
It helps manage large amounts of information in a limited space
by showing only the section headers initially and revealing content on interaction.

Accordion is commonly used for:

* FAQ sections: displaying questions as headers with answers revealed on click
* Forms: organizing long forms into sections, for example, personal info, shipping, and payment
* Menus: nested navigation in sidebars or mobile views

\[DEMO: AccordionDemos.configurator]

## Change chevron

Use the `chevron` prop to change the chevron icon. When `chevron` is set,
`chevronIconSize` prop is ignored. To remove the chevron icon, use `chevron={null}`.

To customize chevron styles, use [Styles API](/styles/styles-api/) with
[data-rotate](/styles/data-attributes/) attribute. It is set when the item
is opened if the `disableChevronRotation` prop is not set.

Example of a custom chevron icon with rotation styles:

\[DEMO: AccordionDemos.chevron]

I see what you mean here, definitely tweaking it a bit still.

@brookton
Copy link
Author

brookton commented Jul 21, 2025

@rtivital I've made some changes which should be ready for re-review.

I wanted to note this adds a few dependencies:

 "gray-matter": "^4.0.3",
 "remark-mdx": "^3.1.0",
 "remark-parse": "^11.0.0",
 "remark-stringify": "^11.0.0",
 "unified": "^11.0.5",
 "unist-util-visit": "^5.0.0",

I'm usually more keen on not adding dependencies whenever possible, let me know if you see a different way I could go about it to reduce this.

I did break out two seperate scripts located in

scripts/
├── llm/                    
│   ├── compile-llm-max-file-size.ts   # Generates a pack of files with limits of 256kb       
│   ├── compile-llm-txt.ts             # Generates the single LLM.txt      

If you take a look at the new LLM.txt blob you'll notice that accordion now spans from line 12 to line 542 and includes all that compiled info.

I'm not entirely sure if the max-file-size is something you'd want to include here but figured I'd throw it in just incase, I might remove those generated files from this commit though.

@rtivital
Copy link
Member

  • Some leftovers to remove: <StylesApiSelectors component="Accordion" />, KeyboardEventsTable, probably others
  • Props descriptions still missing, crucial part of components – https://mantine.dev/core/accordion/?t=props
  • Better to convert internal links [Styles API](/styles/styles-api/) -> [Styles API](https://mantine.dev/styles/styles-api/)
  • Some demos include multiple files, in the output there is only one file, data is missing, see first accordion demo:
## Usage

Accordion allows users to expand and collapse sections of content.
It helps manage large amounts of information in a limited space
by showing only the section headers initially and revealing content on interaction.

Accordion is commonly used for:

* FAQ sections: displaying questions as headers with answers revealed on click
* Forms: organizing long forms into sections, for example, personal info, shipping, and payment
* Menus: nested navigation in sidebars or mobile views

#### Example: configurator

/`/`/`tsx
import { Accordion } from '@mantine/core';
import { data } from './data';

function Demo() {
  const items = data.map((item) => (
    <Accordion.Item key={item.value} value={item.value}>
      <Accordion.Control icon={item.emoji}>{item.value}</Accordion.Control>
      <Accordion.Panel>{item.description}</Accordion.Panel>
    </Accordion.Item>
  ));

  return (
    <Accordion defaultValue="Apples">
      {items}
    </Accordion>
  );
}
/`/`/`

- scripts/llm/compile-llm-doc.ts generates a static LLM.md file
- file contains all demo code, prop descriptions, styles api data for
each component
- scripts/llm/compile-llm-by-size.ts generates sized files seperated by
logical concern with filesize max of 256kb
- outputs files into a directory ./llm-docs
- yarn compile:llm
- yarn compile:llm:size
@brookton
Copy link
Author

Thank you @rtivital, I've addressed all your feedback:

  • Expanded removal list of component references
  • Props descriptions included
  • Internal links converted
  • Multi-file demo extraction complete
  • Code block formatting fixed
  • Verified fixes across 5+ components (Button, Modal, DatePicker, Table, Tabs) to ensure all criteria are consistently met.

Both compile-llm-doc.ts and compile-llm-by-size.ts scripts have been updated with identical fixes.

I squashed my commits, sorry for the force pushes I was arm wrestling with git for a minute there.

Should be ready for re-review.

@rtivital
Copy link
Member

Leftovers:

  • <AutoContrast component="Button" />
  • <ComboboxData component="Autocomplete" />
  • <ComboboxFiltering component="Autocomplete" />
  • <ComboboxLargeData component="Autocomplete" />
  • <FlexboxGapSupport component="Flex" />
  • <GetElementRef component="Input" refType="input" />
  • <Gradient component="Text" />
  • <InputAccessibility component="Autocomplete" />
  • <InputFeatures component="ColorInput" element="input" />
  • <InputSections component="ColorInput" />
  • <Polymorphic defaultElement="button" changeToElement="a" component="ActionIcon" withNext />
  • <ServerComponentsIncompatible component="CopyButton" />
  • <TargetComponent component="HoverCard" />
  • <WrapperProps component="Radio" />

Content of these components is usually important for understanding the component. It is better to include the content of those in llm.txt. https://github.com/mantinedev/mantine/tree/master/apps/mantine.dev/src/components/MdxProvider/MdxSharedContent

  - Add extraction and rendering of MdxSharedContent components
  - Preserve original JSX examples (e.g., <Polymorphic />, <GetElementRef />)
  - Include educational content from AutoContrast, Gradient, InputFeatures, etc.
  - Handle component-specific props (withVariant, refType, element)
  - Convert MDX component output to markdown format
  - Fix escape character issues in JSX rendering
@brookton
Copy link
Author

Thanks for your help with this @rtivital! I'm a huge fan of Mantine and glad to be contributing.

I believe I've addressed your concerns about the shared content components.
Instead of removing them, the scripts now:

  • Preserve the original JSX examples
    • Components like <Polymorphic defaultElement="button" changeToElement="a" component="ActionIcon" withNext /> are kept and real usage with specific props are included
  • Include the educational content
    • Each component's documentation is rendered below its JSX example (e.g., AutoContrast explains the color contrast feature, GetElementRef shows TypeScript ref usage, etc.)
  • Handle all component props properly
    • The content adapts based on props like withVariant, refType, element, etc. to match what the React components would render

The output now looks like:

  <Polymorphic defaultElement="button" changeToElement="a" component="ActionIcon" withNext />

  ## Polymorphic component

  ActionIcon is a polymorphic component – its default root element is button, but it can be changed to any other element or component
  with component prop:
  [... rest of content ...]

Hopefully this addresses your comment. Let me know if you'd like any adjustments!

@rtivital
Copy link
Member

Looking better already, several other fixes left:

  1. Remove changelogs ### Changelog810 ... – there is duplicateinformation
  2. Metadata leftovers from help.mantine.dev articles
export const meta = {
  title:
    'Why can I not use value/label data structure with Autocomplete/TagsInput?',
  description:
    'Learn the difference between Autocomplete and Select components',
  slug: 'autocomplete-value-label',
  category: 'forms',
  tags: [
    'autocomplete',
    'tags-input',
    'data',
    'select',
    'multi-select',
    'MultiSelect',
  ],
  created_at: 'July 15, 2024',
  last_updated_at: 'July 15, 2024',
};
  1. Some help.mantine.dev articles are broken. They also do not include demo code. See https://raw.githubusercontent.com/mantinedev/mantine/refs/heads/master/apps/help.mantine.dev/src/pages/q/align-input-button.mdx for reference.
--------------------------------------------------------------------------------

## FREQUENTLY ASKED QUESTIONS


AlignInputButton,
AlignInputButtonCorrect,
AlignInputButtonStyles,
} from '@/demos/AlignInputButton.demo';

export const meta = {
  title: 'How to align input with a button in a flex container?',
  description:
    'Learn how to align Mantine inputs with buttons using Group component',
  slug: 'align-input-button',
  category: 'styles',
  tags: ['inputs', 'button', 'flexbox', 'centering'],
  created_at: 'February 15, 2024',
  last_updated_at: 'February 15, 2024',
};

If you try to align one of Mantine inputs in a flex container with a button,
you will notice that input is not aligned with the button. This happens because
Mantine inputs have associated elements: label, description and error message.



To align input with a button, you can either use `inputContainer` prop to wrap the button
next to the in a flex container:



Or change error/description position to absolute with [Styles API](https://mantine.dev/styles/styles-api/):




----------------------------------------

@brookton
Copy link
Author

Thanks for the feedback @rtivital! Glad we're getting closer.

Just to confirm you want all changelog information ignored for the scripts?
I've pushed that change to a commit but want to confirm incase you'd expect any unique information living in them that you'd want me to add logic to find and include or something.

Chipping away at the rest now as well!

brookton added 5 commits July 23, 2025 11:54
…size restricted script

- compile-llm-by-size isn't incredibly useful, llms can grep as needed, once single script is polished it'll be easier to extract into this feature later
The script now properly handles:
  - FAQ articles with embedded code blocks (preserving imports)
  - FAQ articles with separate demo files
  - Multi-demo files where multiple exports exist in one file
  - Multi-file demos with code arrays
@brookton
Copy link
Author

brookton commented Jul 23, 2025

Howdy @rtivital,

I believe I've addressed all your comments.
I removed those left over / broken imports from the FAQ page generation.
Extracted the demo code and multi demos successfully per question as well.
For meta removal I opted to extract the title and description, placing the title as an H1 with the description below it.
To reference the same component sample here's what's generated now for the align input faq mdx file:


# How to align input with a button in a flex container?
Learn how to align Mantine inputs with buttons using Group component

If you try to align one of Mantine inputs in a flex container with a button,
you will notice that input is not aligned with the button. This happens because
Mantine inputs have associated elements: label, description and error message.

#### Example: AlignInputButton

```tsx
import { Button, Group, TextInput } from '@mantine/core';

function Demo() {
  return (
    <Group align="flex-end">
      <TextInput label="Your email" error="Something went wrong" />
      <Button>Submit</Button>
    </Group>
  );
}
```

To align input with a button, you can either use `inputContainer` prop to wrap the button
next to the in a flex container:

#### Example: AlignInputButtonCorrect

```tsx
import { Button, Group, TextInput } from '@mantine/core';

function Demo() {
  return (
    <TextInput
      label="Your email"
      error="Something went wrong"
      inputContainer={(children) => (
        <Group align="flex-start">
          {children}
          <Button>Submit</Button>
        </Group>
      )}
    />
  );
}
```

Or change error/description position to absolute with [Styles API](https://mantine.dev/styles/styles-api/):

#### Example: AlignInputButtonStyles

```tsx
import { Button, Group, TextInput } from '@mantine/core';
import classes from './Demo.module.css';

function StylesDemo() {
  return (
    <Group align="flex-end" pb={18}>
      <TextInput label="Your email" error="Something went wrong" classNames={classes} />
      <Button>Submit</Button>
    </Group>
  );
}
```

 ---

@brookton
Copy link
Author

I believe I've resolved the lint issues that were causing pipeline failure before.

Additionally I've drafted a frontend route for you and modified the script to actually output the llms.txt following the https://llmstxt.org/ standard

Here's a screenshot of the drafted route:

screencapture-localhost-7545-guides-llms-2025-07-23-14_14_10

@rtivital
Copy link
Member

Great, final changes left, please do the following:

  • Fix reported CI errors (npm test locally to validate)
  • Remove LLM.md from the repository (it was needed only for the review)
  • Add llms.txt to .gitignore (the file must not be shipped with the repository)

@brookton
Copy link
Author

Amazing!

Thanks again for your help with this @rtivital. It's been a pleasure.

Completed all those changes, should be finalized now! 🎉🥳🎊

@brookton
Copy link
Author

brookton commented Aug 1, 2025

Hey @rtivital

I noticed some additional issues and pushed some important changes.

  • Added complete extraction of CSS selectors, CSS variables, and data attributes from styles-api
    files
  • Improved template literal parsing to handle complex nested expressions (e.g.,
    ${Object.keys().map()})
  • Fixed variable interpolation in multi-file demos (e.g., ${tsxCode}, ${cssCode})
  • Handles escaped characters properly ($ → $, `` → )
  • Fixed issue where import statements in demo code were being incorrectly removed
  • Added proper style import comments for all packages that require them
  • Fixed package name resolution (e.g., @mantine/code-highlight instead of @mantine/x)

I outputted the LLM.md again for you to compare if you'd like. But I believe this to be a comprehensive generative script now. If you notice any other errors in that output though please let me know, but I'll remove the LLM.md file and generation for my next commit so it's ready to ship.

Thanks so much again,

David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants