Skip to content

Commit 0233048

Browse files
michaelmkrausnmergetmfranzkeCopilot
authored
Documentation for dev and copilot (#4384)
* feat(doc): add basic copilot-instructions.md and llms.txt * chore(): add typedoc to project * chore(): add basic adr for copilot documentation * docs(): add some documentation for component to test generation with typedoc * feat(): add postinstall script to copy copilot instruction to corresponding file * docs: document automated postinstall propagation of copilot-instructions.md * feat: add generate-copilot-instructions script with PascalCase folder/file filtering * docs: document automated generation of copilot-instructions.md by including component documentation * docs: adapt jsdoc for button and its models * chore: add plugin to merge typedoc files * feat: append component doc to existing instructions instead of overwriting them completely * chore: add typedoc for doc generation * chore: remove comment * feat: merge component documentations into [MyComponent].md files and copy them to component folder * feat: restructure script and add comments * chore: delete existing md files within button docs folder * feat: add script to generate framework-specific code snippets * feat: use mitosis plugin instead of script to generate examples * feat: append example snippets for react, angular and vue to [component].md * feat: introduce sassdoc to generate md documentation for SCSS and integrate it into [component].md * feat: add script to extract sassdoc and save in md * chore: move scripts to documentation subfolder * chore: add readme describing how to generate copilot-instructions.md * chore: adapt readme describing how to generate copilot-instructions.md * feat: fix typos in readme * chore: adapt skript calls and readme * chore: moved script calls to scripts/package.json and adapt README * chore: moved typedoc.json to scripts folder * feat: add sassdoc comments to variables for drawer * docs: add examples for SassDoc and JSDoc * feat: only handle defined components and skip others * docs: added open points to readme * feat: also copy all component-md files to docs/copilot folder * chore: add new cli tool to copy docs to project * fix: issues with bad docs folder * fix: linting issue * fix: issues with extract-css-vars.ts * chore: update button.docs.lite.tsx * feat: improve copilot * fix: issues with agent directories * chore: add remaining component examples * chore: add agent-cli to build outputs * chore: add agent-cli to build outputs * fix: issue with agent-cli bin * chore: improve some ai related stuff * Update README.md * Update packages/foundations/agent/_instructions.md Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * Update packages/foundations/agent/_instructions.md Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * Update scripts/documentation/merge-component-docs.ts Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * Update packages/foundations/agent/_instructions.md Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * Update packages/agent-cli/package.json Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * Update packages/agent-cli/package.json Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * Update packages/agent-cli/README.md * refactor: regenerated package lock file * docs: copilot documentation documentation (#4651) * refactor: enhanced documentation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update packages/agent-cli/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/agent-cli/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * docs: provide further information * docs: added sample prompt * chore: update package-lock.json * fix: linting issues * fix: linting issues * Update docs/adr/adr-05-copilot-developer-doc.md Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * Update docs/adr/adr-05-copilot-developer-doc.md Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * Update packages/foundations/agent/css/Variables.md Co-authored-by: Michael Kraus <michael.m.kraus@deutschebahn.com> * Update docs/adr/adr-05-copilot-developer-doc.md Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * Update packages/agent-cli/src/copilot/index.ts Co-authored-by: Michael Kraus <michael.m.kraus@deutschebahn.com> * Update packages/foundations/agent/_instructions.md Co-authored-by: Michael Kraus <michael.m.kraus@deutschebahn.com> * Update packages/foundations/agent/_instructions.md Co-authored-by: Michael Kraus <michael.m.kraus@deutschebahn.com> * Update packages/foundations/agent/_instructions.md Co-authored-by: Michael Kraus <michael.m.kraus@deutschebahn.com> * Update packages/foundations/agent/_instructions.md Co-authored-by: Michael Kraus <michael.m.kraus@deutschebahn.com> * Update packages/foundations/agent/scss/Variables.md Co-authored-by: Michael Kraus <michael.m.kraus@deutschebahn.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Michael Kraus <michael.m.kraus@deutschebahn.com> Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * chore: update package-lock.json * Apply suggestions from code review * Update packages/agent-cli/package.json Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * Update packages/agent-cli/test/index.spec.ts * Apply suggestions from code review * Update packages/foundations/package.json * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> --------- Co-authored-by: Nicolas Merget <nicolas.merget@deutschebahn.com> Co-authored-by: Nicolas Merget <104347736+nmerget@users.noreply.github.com> Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> Co-authored-by: Maximilian Franzke <Maximilian.Franzke@deutschebahn.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e15fa6d commit 0233048

File tree

88 files changed

+7068
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+7068
-62
lines changed

.changeset/sour-brooms-tie.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@db-ux/ngx-core-components": patch
3+
"@db-ux/react-core-components": patch
4+
"@db-ux/wc-core-components": patch
5+
"@db-ux/v-core-components": patch
6+
"@db-ux/agent-cli": patch
7+
"@db-ux/core-components": patch
8+
"@db-ux/core-foundations": patch
9+
---
10+
11+
enabled [`@db-ux/agent-cli`](https://www.npmjs.com/package/@db-ux/agent-cli) for every package to
12+
auto-generate/auto-update `.github/copilot-instructions.md`, to ensure GitHub Copilot
13+
uses DB UX Components for code generation

.config/.jscpd.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"**/.next/**",
1313
"**/.nuxt/**",
1414
"**/.output/**",
15+
"**/agent/**",
1516
"**/.vscode/**",
1617
"**/*-example/index.html",
1718
"**/*-showcase/index.html",

.github/workflows/01-build-outputs.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ jobs:
4242
name: db-ux-stylelint-build
4343
path: packages/stylelint/build
4444

45+
- name: ⏬ Download agent-cli build
46+
uses: actions/download-artifact@v4
47+
with:
48+
name: db-ux-agent-cli-build
49+
path: packages/agent-cli/build
50+
4551
- name: ⏬ Download output
4652
uses: actions/download-artifact@v5
4753
with:
@@ -54,7 +60,9 @@ jobs:
5460
install-command: npm i
5561

5662
- name: 🔨 Build outputs
57-
run: npm run build-outputs
63+
run: |
64+
npm run generate:agent
65+
npm run build-outputs
5866
5967
- name: 📦 Validate Package Publishing
6068
run: |

.github/workflows/01-build-packages.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ jobs:
5050
with:
5151
name: db-ux-stylelint-build
5252
path: packages/stylelint/build
53+
54+
- name: ⏫ Upload agent-cli build
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: db-ux-agent-cli-build
58+
path: packages/agent-cli/build

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
node_modules
3+
!packages/agent-cli/test/**/node_modules
34
npm-debug.log
45
.history
56
.idea
@@ -66,4 +67,7 @@ showcases/patternhub/public/iframe-resizer/*
6667
/scripts/public/
6768
/scripts/gh-pages.tar.gz
6869
!/scripts/tests/fixtures/out
70+
/output/**/docs/
71+
/output/**/agent/
72+
/packages/agent-cli/test/.github/copilot-instructions.md
6973
/core-web.iml

.markdownlintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ build-outputs/**
77
build-showcases/**
88
showcases/**/public/**
99
CODE-OF-CONDUCT.md
10+
**/agent/**
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# ADR 2025-06-10: Documentation strategy for GitHub Copilot and developer docs
2+
3+
## Context
4+
5+
We need a consistent, maintainable documentation approach that serves both developers and AI-assisted coding
6+
tools (GitHub Copilot) without duplicating effort. The documentation must cover component usage, variants, props,
7+
examples, and allow Copilot to answer questions like "What variants does the Button support?" without manually
8+
opening multiple files.
9+
10+
Key requirements:
11+
12+
- Single source of truth for component documentation.
13+
- Automatic inclusion of context in Copilot Chat for both IDEs, VS Code and IntelliJ.
14+
- Developer-friendly Markdown for manual reading and static site generation.
15+
- Compatibility with LLM context conventions (llms.txt; to be integrated in a later phase) and GitHub Copilot Custom Instructions (`copilot-instructions.md`).
16+
17+
## Decision
18+
19+
1. Documentation Format & Location
20+
21+
- Use Markdown files per component, stored in packages/components/docs/ or packages/components/src/components/docs/.
22+
- Central table of contents in docs/llms.txt listing all component docs with relative paths.
23+
24+
2. GitHub Copilot Custom Instructions
25+
26+
- Place `copilot-instructions.md` in the project root (under .github/) to provide global guidance.
27+
- Instruct Copilot Chat to load this file automatically; it will include links to llms.txt and recommended file paths.
28+
29+
3. Automatic Context Loading
30+
31+
- In VS Code and IntelliJ, Copilot Chat will automatically read `.github/copilot-instructions.md` on new chats.
32+
- To surface specific details, embed documentation (e.g., Button.md) directly in `copilot-instructions.md`.
33+
34+
4. Interactive Context Attachment
35+
36+
- For deeper or ad-hoc queries, use the "Attach Context" feature in Copilot Chat to load component Markdown files during the session.
37+
38+
5. Static Site & Developer Docs (future usage, not part of the current scope)
39+
40+
- Integrate component docs via Astro as a package in the monorepo, referencing Markdown sources in packages/components/... .
41+
- Render pages dynamically under /components/[slug] and /api/[slug] for manual browsing.
42+
43+
6. Automated Propagation of Copilot Instructions
44+
45+
We add a `postinstall` hook to our component package that:
46+
47+
- copies or appends the package-specific file `.github/copilot-instructions.md` to the target project,
48+
- uses unique markers to automatically replace outdated blocks during future installations,
49+
- handles missing or already existing files as well as idempotent updates cleanly, ensuring that every installation immediately provides the latest Copilot context for our package.
50+
51+
7. Automate generation and propagation of Copilot instructions on package build.
52+
53+
- Define `generate:agent` in `package.json` and hook into `prepare`.
54+
- Only include `*.md` files whose filename matches the parent directory converted to PascalCase (e.g. `custom-select``CustomSelect.md`), ensuring no unrelated MDs are merged.
55+
56+
## Alternatives Considered
57+
58+
- Rely solely on Code Search: Let Copilot use workspace search to locate docs dynamically. Rejected due to inconsistency and limited to agent mode.
59+
- TypeDoc-only approach: Generate API docs from TypeScript. Provides type detail but lacks usage narratives and cross-framework examples.
60+
- Mitosis Metadata Model: Embed JSON metadata via useMetadata and generate docs. Promising, but requires custom plugins and not widely adopted yet.
61+
62+
## Consequences
63+
64+
- Pros:
65+
66+
- Clear separation: manual design guidance (Markdown) vs. AI context (`copilot-instructions.md` + `llms.txt` snippets).
67+
- Maintains single source (docs in packages/components/docs).
68+
- Enables Copilot to provide accurate, component-specific suggestions without manual file opening.
69+
- Developer site generation remains straightforward via Astro.
70+
- Consumers always receive the latest Copilot context without manual steps.
71+
- Guarantees that only the intended component documentation is merged into Copilot instructions.
72+
73+
- Cons:
74+
- Requires maintaining excerpts in `copilot-instructions.md` when docs change.
75+
- Copilot cannot truly auto-load all linked docs; manual attachment or excerpt embedding needed for deep context.
76+
- Postinstall hooks may be disabled for security reasons, making it impossible to automate the copying of the copilot instructions.
77+
- Relies on strict naming conventions; any divergence between folder and file names will cause a component’s docs to be skipped.

output/angular/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ There are 3 ways to use Events in Angular:
113113
></db-input>
114114
```
115115

116+
## Documentation for AI Agents
117+
118+
We provide a documentation for every component in the DB UX Design System via `docs` folder.
119+
To consume those documentation for AI Agents (currently GitHub Copilot) the best way is to copy the `docs` folder into your project.
120+
121+
We provide a [CLI tool (`@db-ux/agent-cli`)](https://www.npmjs.com/package/@db-ux/agent-cli) to do this automatically, which you can run with:
122+
123+
```shell
124+
npx @db-ux/agent-cli
125+
```
126+
116127
## Deutsche Bahn brand
117128

118129
As we'd like to perfectly support our users and customers on their digital journey, the usage of Deutsche Bahn brand and trademarks are bound of clear guidelines and restrictions even if being used with the code that we're providing with this product; Deutsche Bahn fully reserves all rights regarding the Deutsche Bahn brand, even though that we're providing the code of DB UX Design System products free to use and release it under the Apache 2.0 license.

output/angular/agent/.gitkeep

Whitespace-only changes.

output/angular/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"types": "index.d.ts",
1414
"scripts": {
1515
"build": "ng build",
16+
"mv:agent": "cpr agent ../../build-outputs/angular/agent --overwrite",
1617
"ng": "ng",
18+
"postbuild": "npm-run-all --parallel mv:*",
1719
"start": "ng serve"
1820
},
1921
"devDependencies": {

0 commit comments

Comments
 (0)