-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopilotApi.js
More file actions
48 lines (42 loc) · 1.91 KB
/
copilotApi.js
File metadata and controls
48 lines (42 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Feature: VS Code Copilot API integration
// Why: Enables orchestrator to prompt Copilot for code suggestions and fixes
// Filepath: copilotApi.js
// Description: Provides a function to prompt Copilot in VS Code and return suggestions
// Trace: Used by orchestrator.service.js for automated code fixes
// NOTE: This file is now split for two contexts:
// 1. Orchestrator automation (Node.js, backend)
// 2. VS Code extension (frontend, Copilot API)
const fs = require('fs');
const GeminiAgent = require('./.github/agent/gemini-agent');
/**
* promptCopilot - Sends a prompt to Copilot and returns suggestions
* @param {string} prompt - The prompt/question for Copilot
* @returns {Promise<string[]>} - Array of Copilot suggestions
*/
async function promptCopilot(prompt) {
// Use GeminiAgent to generate code suggestions
const suggestion = await GeminiAgent.generateCode(prompt);
return [suggestion];
}
/**
* autoFixWithCopilot - Prompts Copilot for a fix that accommodates the gate rule and applies it to the file
* @param {string} gateRule - The gate rule description (e.g., 'Type Enforcement: models/types required')
* @param {string} filePath - The path to the file to fix
* @param {string} errorMsg - The error message from the gate
* @returns {Promise<boolean>} - True if fix applied, false otherwise
*/
async function autoFixWithCopilot(gateRule, filePath, errorMsg) {
const prompt = `Fix the file at ${filePath} to satisfy this gate rule: ${gateRule}. Error: ${errorMsg}`;
try {
const suggestions = await promptCopilot(prompt);
if (!suggestions || suggestions.length === 0) throw new Error('No Gemini suggestions');
// Use the first suggestion as the fix
const fs = require('fs');
fs.writeFileSync(filePath, suggestions[0], 'utf8');
return true;
} catch (err) {
console.error('Gemini auto-fix failed:', err);
return false;
}
}
module.exports = { promptCopilot, autoFixWithCopilot };