Skip to content

Commit a7ba3a1

Browse files
Merge pull request #115 from codacy/windsurf-workflows
feat: create workflows for windsurf
2 parents ede75d3 + f14433b commit a7ba3a1

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

src/commands/configureMCP.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { CodacyCli } from '../cli/CodacyCli'
99
import Logger from '../common/logger'
1010
import { CodacyError, Config } from '../common'
1111
import { RepositoryParams } from '../git/CodacyCloud'
12+
import { createWindsurfWorkflows } from './createWorkflows'
1213

1314
interface Rule {
1415
when?: string
@@ -495,6 +496,9 @@ export async function configureMCP(params?: RepositoryParams, isUpdate = false)
495496
}
496497

497498
await createOrUpdateRules(params)
499+
if (ide === 'windsurf') {
500+
createWindsurfWorkflows()
501+
}
498502
} catch (error) {
499503
throw new CodacyError('Failed to configure MCP server', error as Error, 'MCP')
500504
}

src/commands/createWorkflows.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import * as vscode from 'vscode'
2+
import * as fs from 'fs'
3+
import * as path from 'path'
4+
import Logger from '../common/logger'
5+
6+
type Workflow = {
7+
name: string
8+
description: string
9+
content: string
10+
}
11+
12+
const workflows: Workflow[] = [
13+
{
14+
name: 'codacy-fix-issues',
15+
description: 'Find and fix issues in your project using Codacy local analysis',
16+
content: `
17+
If the user gave you files as context:
18+
19+
1. Run the 'codacy_cli_analyze' tool for each of the files given as context, with the following params:
20+
- rootPath: set to the workspace path
21+
- file: set to the path of the file
22+
- tool: leave empty or unset
23+
2. If any issues are found in the files, propose and apply fixes for them.
24+
3. If you encounter that Codacy is applying a tool to the project that it shouldn't, don't try to find the configuration of Codacy, just let the user know it's a false positive issue.
25+
26+
If the user didn't provide any files as context:
27+
28+
1. Ask the user which files they want to analyse.
29+
2. Analyse the files they answer with by running 'codacy_cli_analyze' tool for each file, with the following params:
30+
- rootPath: set to the workspace path
31+
- file: set to the path of the file
32+
- tool: leave empty or unset
33+
3. If any issues are found in the files, propose and apply fixes for them.
34+
4. If you encounter that Codacy is applying a tool to the project that it shouldn't, don't try to find the configuration of Codacy, just let the user know it's a false positive issue.`,
35+
},
36+
{
37+
name: 'codacy-check-coverage',
38+
description: 'Check code coverage of your project using Codacy',
39+
content: `
40+
1. Call 'codacy_get_file_coverage' tool for each of the files given as context
41+
2. If any files are missing coverage, propose and apply fixes for them
42+
`,
43+
},
44+
]
45+
46+
export const createWindsurfWorkflows = () => {
47+
const workspacePath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath
48+
if (!workspacePath) {
49+
throw new Error('No workspace folder found')
50+
}
51+
const fileFolder = path.join(workspacePath, '.windsurf', 'workflows')
52+
if (!fs.existsSync(fileFolder)) {
53+
fs.mkdirSync(fileFolder, { recursive: true })
54+
}
55+
workflows.forEach((workflow) => {
56+
const filePath = path.join(fileFolder, `${workflow.name}.md`)
57+
fs.writeFileSync(
58+
filePath,
59+
`---
60+
description: ${workflow.description}
61+
---
62+
${workflow.content}`
63+
)
64+
})
65+
Logger.appendLine(`Generated workflow files`)
66+
}

0 commit comments

Comments
 (0)