Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/agent-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ Use this command in your repository:
npx @db-ux/agent-cli
```

Or with pnpm:

```shell
pnpm exec @db-ux/agent-cli
```

The DB UX Design System documentation will be added to (or replaced in subsequent runs, e.g. after a DB UX Design System update) in the file `.github/copilot-instructions.md` (if this file does not yet exist in your codebase, it will be created).

**Note:** The tool works with all package managers (npm, yarn, pnpm) and correctly handles symlinked packages in pnpm's node_modules structure.

### Advanced Usage

You can also change the root path where the tool should check for `node_modules`:
Expand Down
36 changes: 26 additions & 10 deletions packages/agent-cli/src/copilot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ function findAllNodeModulesDirectories(
.readdirSync(directory, { withFileTypes: true })
.sort((a, b) => a.name.localeCompare(b.name, 'en'));
for (const entry of entries) {
if (entry.isDirectory()) {
const fullPath = path.join(directory, entry.name);
// Use statSync to follow symlinks (important for pnpm compatibility)
let isDirectory = false;
try {
isDirectory = fs.statSync(fullPath).isDirectory();
} catch {
// Skip entries that can't be accessed
continue;
}

if (isDirectory) {
if (entry.name === 'node_modules') {
found.push(path.join(directory, entry.name));
found.push(fullPath);
} else if (!entry.name.startsWith('.')) {
findAllNodeModulesDirectories(
path.join(directory, entry.name),
found
);
findAllNodeModulesDirectories(fullPath, found);
}
}
}
Expand Down Expand Up @@ -54,18 +61,27 @@ export const generateCopilot = (rootPath: string) => {
withFileTypes: true
});
for (const package_ of packages) {
if (package_.isDirectory()) {
const packagePath = path.join(databaseUxPath, package_.name);
// Use statSync to follow symlinks (important for pnpm compatibility)
let isDirectory = false;
try {
isDirectory = fs.statSync(packagePath).isDirectory();
} catch {
// Skip entries that can't be accessed
continue;
}

if (isDirectory) {
const instructionsPath = path.join(
databaseUxPath,
package_.name,
packagePath,
'agent',
'_instructions.md'
);
if (fs.existsSync(instructionsPath)) {
let content = fs.readFileSync(instructionsPath, 'utf8');
const relativePath = path.relative(
rootPath,
path.join(databaseUxPath, package_.name)
packagePath
);
content = content
.replaceAll(
Expand Down
4 changes: 2 additions & 2 deletions packages/agent-cli/test/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ exports[`default > check if docs are created 1`] = `
--- START: DB UX Copilot Instructions – do not edit below ---

# @db-ux/components
- use y for frontend/node_modules/@db-ux/components/test.md
- use y for node_modules/@db-ux/components/test.md


# @db-ux/foundations
- use x for frontend/node_modules/@db-ux/foundations/test.md
- use x for node_modules/@db-ux/foundations/test.md


--- END: DB UX Copilot Instructions – do not edit above ---
Expand Down
13 changes: 13 additions & 0 deletions packages/agent-cli/test/frontend/.github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- START: DB UX Copilot Instructions – do not edit below ---

# @db-ux/components
- use y for node_modules/@db-ux/components/test.md


# @db-ux/foundations
- use x for node_modules/@db-ux/foundations/test.md


---

END: DB UX Copilot Instructions – do not edit above ---
20 changes: 18 additions & 2 deletions packages/agent-cli/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,26 @@ import { generateCopilot } from '../src/copilot';
describe('default', () => {
test('check if docs are created', async () => {
const copilotFile = path.resolve(
'test/.github/copilot-instructions.md'
'test/frontend/.github/copilot-instructions.md'
);
generateCopilot('test');
generateCopilot('test/frontend');

expect(fs.readFileSync(copilotFile).toString()).toMatchSnapshot();
});

test('check if docs are created from pnpm symlinked packages', async () => {
const copilotFile = path.resolve(
'test/pnpm-test/.github/copilot-instructions.md'
);
generateCopilot('test/pnpm-test');

const content = fs.readFileSync(copilotFile).toString();

// Verify that the symlinked package was detected and processed
expect(content).toContain('test-symlink-package');
expect(content).toContain('Symlinked Package Instructions');
expect(content).toContain(
'This is a test package accessed via symlink'
);
});
});
11 changes: 11 additions & 0 deletions packages/agent-cli/test/pnpm-test/.github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- START: DB UX Copilot Instructions – do not edit below ---

# @db-ux/test-symlink-package
# Symlinked Package Instructions

This is a test package accessed via symlink (simulating pnpm structure).


---

END: DB UX Copilot Instructions – do not edit above ---

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.