Skip to content

Commit e7bf98b

Browse files
committed
chore: improve some ai related stuff
1 parent 6170dde commit e7bf98b

File tree

2 files changed

+72
-39
lines changed

2 files changed

+72
-39
lines changed

packages/agent-cli/src/copilot/index.ts

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,81 @@
1-
import fs from 'fs';
2-
import path from 'path';
1+
import fs from 'node:fs';
2+
import path from 'node:path';
33

4-
function findAllNodeModulesDirs(dir: string, found: string[] = []): string[] {
5-
if (!fs.existsSync(dir)) return found;
6-
const entries = fs.readdirSync(dir, { withFileTypes: true });
4+
function findAllNodeModulesDirectories(
5+
directory: string,
6+
found: string[] = []
7+
): string[] {
8+
if (!fs.existsSync(directory)) {
9+
return found;
10+
}
11+
12+
const entries = fs.readdirSync(directory, { withFileTypes: true });
713
for (const entry of entries) {
814
if (entry.isDirectory()) {
915
if (entry.name === 'node_modules') {
10-
found.push(path.join(dir, entry.name));
16+
found.push(path.join(directory, entry.name));
1117
} else if (!entry.name.startsWith('.')) {
12-
findAllNodeModulesDirs(path.join(dir, entry.name), found);
18+
findAllNodeModulesDirectories(
19+
path.join(directory, entry.name),
20+
found
21+
);
1322
}
1423
}
1524
}
25+
1626
return found;
1727
}
1828

1929
export const generateCopilot = (rootPath: string) => {
2030
const outputFolder = path.resolve(rootPath, '.github');
2131

22-
const nodeModulesDirs = findAllNodeModulesDirs(rootPath);
23-
if (nodeModulesDirs.length === 0) {
32+
const nodeModulesDirectories = findAllNodeModulesDirectories(rootPath);
33+
if (nodeModulesDirectories.length === 0) {
2434
console.error('No node_modules folders found.');
2535
return;
2636
}
2737

2838
let copilotInstructionsContent = '';
2939

30-
for (const nodeModulesPath of nodeModulesDirs) {
31-
const dbUxPath = path.join(nodeModulesPath, '@db-ux');
32-
if (!fs.existsSync(dbUxPath)) {
33-
continue;
34-
}
35-
const packages = fs.readdirSync(dbUxPath, { withFileTypes: true });
36-
for (const pkg of packages) {
37-
if (pkg.isDirectory()) {
38-
const instructionsPath = path.join(
39-
dbUxPath,
40-
pkg.name,
41-
'agent',
42-
'_instructions.md'
43-
);
44-
if (fs.existsSync(instructionsPath)) {
45-
let content = fs.readFileSync(instructionsPath, 'utf-8');
46-
const relPath = path.relative(
47-
rootPath,
48-
path.join(dbUxPath, pkg.name)
49-
);
50-
content = content.replace(
51-
/__agent-path__/g,
52-
relPath.replace(/\\/g, '/')
40+
for (const nodeModulesPath of nodeModulesDirectories) {
41+
const databaseUxPaths = [
42+
path.join(nodeModulesPath, '@db-ux'),
43+
path.join(nodeModulesPath, '@db-ux-inner-source')
44+
];
45+
46+
for (const databaseUxPath of databaseUxPaths) {
47+
if (!fs.existsSync(databaseUxPath)) {
48+
continue;
49+
}
50+
51+
const packages = fs.readdirSync(databaseUxPath, {
52+
withFileTypes: true
53+
});
54+
for (const package_ of packages) {
55+
if (package_.isDirectory()) {
56+
const instructionsPath = path.join(
57+
databaseUxPath,
58+
package_.name,
59+
'agent',
60+
'_instructions.md'
5361
);
54-
copilotInstructionsContent += `\n# @db-ux/${pkg.name}\n${content}\n`;
62+
if (fs.existsSync(instructionsPath)) {
63+
let content = fs.readFileSync(instructionsPath, 'utf8');
64+
const relativePath = path.relative(
65+
rootPath,
66+
path.join(databaseUxPath, package_.name)
67+
);
68+
content = content
69+
.replaceAll(
70+
'__agent-path__',
71+
relativePath.replaceAll('\\', '/')
72+
)
73+
.replaceAll(
74+
'**agent-path**',
75+
relativePath.replaceAll('\\', '/')
76+
);
77+
copilotInstructionsContent += `\n# ${path.basename(databaseUxPath)}/${package_.name}\n${content}\n`;
78+
}
5579
}
5680
}
5781
}
@@ -72,16 +96,16 @@ export const generateCopilot = (rootPath: string) => {
7296
if (copilotInstructionsContent.trim()) {
7397
let copilotFileContent = fs.readFileSync(
7498
copilotInstructionsPath,
75-
'utf-8'
99+
'utf8'
76100
);
77101
const startMarker = '--- START: DB UX Copilot Instructions ---';
78102
const endMarker = '--- END: DB UX Copilot Instructions ---';
79-
const startIdx = copilotFileContent.indexOf(startMarker);
80-
const endIdx = copilotFileContent.indexOf(endMarker);
81-
if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
103+
const startIndex = copilotFileContent.indexOf(startMarker);
104+
const endIndex = copilotFileContent.indexOf(endMarker);
105+
if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {
82106
copilotFileContent = (
83-
copilotFileContent.slice(0, startIdx) +
84-
copilotFileContent.slice(endIdx + endMarker.length)
107+
copilotFileContent.slice(0, startIndex) +
108+
copilotFileContent.slice(endIndex + endMarker.length)
85109
).trim();
86110
}
87111

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Common AI mistakes
2+
3+
### `DBButton` or `db-button`
4+
5+
- available variants are `outline`, `brand`, `filled`, `ghost`
6+
- always use variant `outline` as default
7+
- use variant `brand` as CTA or primary action
8+
- if `noText`/`no-text` property is used add a `DBTooltip` or `db-tooltip` inside the Button
9+
- always add a `type` as property as best practise

0 commit comments

Comments
 (0)