Skip to content

Commit 2eb685d

Browse files
authored
clean: adjust agent rules (#53)
* clean: adjust agent rules * remove commented code * fix problem
1 parent 1157b73 commit 2eb685d

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

src/commands/configureMCP.ts

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,52 @@ interface RuleConfig {
1818
rules: Rule[]
1919
}
2020

21-
const newRulesTemplate = (provider?: string, organization?: string, repository?: string): RuleConfig => ({
22-
name: 'Codacy Rules',
23-
description: 'Configuration for AI behavior when interacting with Codacy',
24-
rules: [
25-
{
21+
const newRulesTemplate = (repository?: Repository): RuleConfig => {
22+
const repositoryRules: Rule[] = []
23+
if (repository) {
24+
const { provider, owner: organization, name } = repository
25+
repositoryRules.push({
2626
when: 'using any tool that has either one of the following arguments: provider, organization or repository',
2727
enforce: [
28-
`use ${provider} for provider, ${organization} for organization and ${repository} for repository, and avoid calling 'git remote -v' unless really necessary`,
28+
`use ${provider} for provider, ${organization} for organization and ${name} for repository, and avoid calling 'git remote -v' unless really necessary`,
2929
],
30-
},
30+
})
31+
}
32+
33+
const commonRules: Rule[] = [
3134
{
3235
when: 'after ANY successful edit_file or reapply tool call',
3336
enforce: [
3437
'IMMEDIATELY run codacy_cli_analyze tool for each edited file with:',
3538
'1. rootPath set to the workspace path',
3639
'2. file set to the edited file path',
40+
'3. no tool',
41+
'AT THE END run codacy_cli_analyze tool for Trivy for the entire project with:',
42+
'1. rootPath set to the workspace path',
43+
'2. no file',
44+
'3. tool set to Trivy',
3745
'If issues are found, propose fixes for them',
3846
],
3947
},
40-
],
41-
})
48+
{
49+
when: 'after adding new dependencies, libraries or packages',
50+
enforce: [
51+
'IMMEDIATELY run codacy_cli_analyze tool for Trivy for:',
52+
'1. rootPath set to the workspace path',
53+
'2. no file',
54+
'3. tool set to Trivy',
55+
'If issues are found, propose fixes for them',
56+
],
57+
},
58+
]
59+
60+
return {
61+
name: 'Codacy Rules',
62+
description: 'Configuration for AI behavior when interacting with Codacy',
63+
rules: [...repositoryRules, ...commonRules],
64+
}
65+
}
66+
4267
// Function to sanitize the JSON content to avoid trailing commas
4368
const sanitizeJSON = (json: string): string => {
4469
return json.replace(/,([\s\r\n]*[}\]])/g, '$1')
@@ -112,9 +137,7 @@ const addRulesToGitignore = (rulesPath: string) => {
112137
}
113138
}
114139
export async function createRules(repository: Repository) {
115-
const { provider, owner: organization, name } = repository
116-
117-
const newRules = newRulesTemplate(provider, organization, name)
140+
const newRules = newRulesTemplate(repository)
118141

119142
try {
120143
const { path: rulesPath, format } = getCorrectRulesInfo()

0 commit comments

Comments
 (0)