cloving 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/init.js +61 -6
- package/dist/commands/unit_tests.js +27 -16
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -22,19 +22,19 @@ const init = async (options) => {
|
|
|
22
22
|
if (specialFileNames.length > 0) {
|
|
23
23
|
console.log(`Cloving will analyze the list of files and the contents of the following files:
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
${specialFileNames.join("\n")}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
Cloving will send AI a request to summarize the technologies used in this project.
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
This will provide better context for future Cloving requests.
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
For increased privacy, you can run \`cloving config\` and make sure to configure a local ollama model (llama3:70b-instruct currently works well for this) so that this data is not sent to an AI service provider.
|
|
32
32
|
`);
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
console.log(`
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
This script will analyze the list of files in the current directory using GPT to summarize the
|
|
37
|
+
technologies used. This will provide better context for future Cloving requests.
|
|
38
38
|
`);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -80,10 +80,65 @@ const init = async (options) => {
|
|
|
80
80
|
${JSON.stringify(projectDetails, null, 2)}
|
|
81
81
|
|
|
82
82
|
Please return JSON-formatted metadata about the project, including:
|
|
83
|
+
|
|
83
84
|
- The programming language(s) used
|
|
84
85
|
- The detected framework(s) (if any)
|
|
85
86
|
- The version of the language(s)
|
|
86
87
|
|
|
88
|
+
Here is a typescript interface for the expected response:
|
|
89
|
+
|
|
90
|
+
interface LanguageConfig {
|
|
91
|
+
name: string
|
|
92
|
+
version?: string
|
|
93
|
+
primary?: boolean
|
|
94
|
+
directory: string
|
|
95
|
+
extension: string
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface FrameworkConfig {
|
|
99
|
+
name: string
|
|
100
|
+
type: string
|
|
101
|
+
version?: string
|
|
102
|
+
primary?: boolean
|
|
103
|
+
directory?: string
|
|
104
|
+
extension?: string
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface TestingFrameworkConfig {
|
|
108
|
+
name: string
|
|
109
|
+
type: string
|
|
110
|
+
version?: string
|
|
111
|
+
directory?: string
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface BuildToolConfig {
|
|
115
|
+
name: string
|
|
116
|
+
type: string
|
|
117
|
+
version?: string
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface LinterConfig {
|
|
121
|
+
name: string
|
|
122
|
+
version?: string
|
|
123
|
+
type?: string
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
interface DatabaseConfig {
|
|
127
|
+
name: string
|
|
128
|
+
primary?: boolean
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface ClovingGPTConfig {
|
|
132
|
+
languages: LanguageConfig[]
|
|
133
|
+
frameworks: FrameworkConfig[]
|
|
134
|
+
testingFrameworks?: TestingFrameworkConfig[]
|
|
135
|
+
buildTools: BuildToolConfig[]
|
|
136
|
+
packageManager: string
|
|
137
|
+
linters: LinterConfig[]
|
|
138
|
+
databases?: DatabaseConfig[]
|
|
139
|
+
projectType: string
|
|
140
|
+
}
|
|
141
|
+
|
|
87
142
|
Here is an example response:
|
|
88
143
|
|
|
89
144
|
{
|
|
@@ -3,9 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 =
|
|
7
|
-
const os_1 = __importDefault(require("os"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
6
|
+
const fs_1 = require("fs");
|
|
9
7
|
const child_process_1 = require("child_process");
|
|
10
8
|
const git_utils_1 = require("../utils/git_utils");
|
|
11
9
|
const cloving_gpt_1 = __importDefault(require("../cloving_gpt"));
|
|
@@ -19,6 +17,18 @@ const extractChangedFiles = (gitDiff) => {
|
|
|
19
17
|
}
|
|
20
18
|
return Array.from(files);
|
|
21
19
|
};
|
|
20
|
+
const setupTestingPrompt = async (gpt, config) => {
|
|
21
|
+
const prompt = `I have the following cloving.json configuration file:
|
|
22
|
+
|
|
23
|
+
==== begin cloving.json ====
|
|
24
|
+
${JSON.stringify(config, null, 2)}
|
|
25
|
+
==== end cloving.json ====
|
|
26
|
+
|
|
27
|
+
Please provide instructions on how to set up testing for this project.`;
|
|
28
|
+
const setupInstructions = await gpt.generateText({ prompt });
|
|
29
|
+
console.log(setupInstructions);
|
|
30
|
+
process.exit(0);
|
|
31
|
+
};
|
|
22
32
|
const generatePrompt = (files, srcFiles, testFiles, gitDiff) => {
|
|
23
33
|
const filesList = files.length > 0 ? files.join('\n') : 'No files provided';
|
|
24
34
|
const diffSection = gitDiff ? `Here is my git diff:\n\n==== begin git diff ====\n${gitDiff}\n==== end git diff ====\n` : '';
|
|
@@ -63,9 +73,10 @@ const unitTests = async (options) => {
|
|
|
63
73
|
const gpt = new cloving_gpt_1.default(options);
|
|
64
74
|
// Read the cloving.json file
|
|
65
75
|
const config = (0, command_utils_1.readClovingConfig)();
|
|
66
|
-
const testingDirectory = config.testingFrameworks
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
const testingDirectory = config.testingFrameworks?.find((framework) => framework.directory)?.directory;
|
|
77
|
+
if (!testingDirectory) {
|
|
78
|
+
await setupTestingPrompt(gpt, config);
|
|
79
|
+
}
|
|
69
80
|
let allSrcFiles = [];
|
|
70
81
|
// Collect srcFiles for each language with specified directory and extension
|
|
71
82
|
for (const language of config.languages) {
|
|
@@ -76,8 +87,8 @@ const unitTests = async (options) => {
|
|
|
76
87
|
}
|
|
77
88
|
// Ensure allSrcFiles is unique
|
|
78
89
|
allSrcFiles = Array.from(new Set(allSrcFiles));
|
|
79
|
-
if (allSrcFiles.length === 0) {
|
|
80
|
-
console.error('Could not find any source files to generate unit tests. Please run: cloving init');
|
|
90
|
+
if (allSrcFiles.length === 0 || !testingDirectory) {
|
|
91
|
+
console.error('Could not find any source files to generate unit tests. Please run: cloving init. Then try again.');
|
|
81
92
|
process.exit(1);
|
|
82
93
|
}
|
|
83
94
|
const testFiles = (0, child_process_1.execFileSync)('find', [testingDirectory, '-type', 'f']).toString().trim();
|
|
@@ -96,28 +107,28 @@ const unitTests = async (options) => {
|
|
|
96
107
|
const lines = [];
|
|
97
108
|
const context = [];
|
|
98
109
|
// Read input from temporary file
|
|
99
|
-
contextFiles.split(
|
|
110
|
+
contextFiles.split('\n').forEach((line) => {
|
|
100
111
|
if (line.trim()) {
|
|
101
112
|
lines.push(line.trim());
|
|
102
113
|
}
|
|
103
114
|
});
|
|
104
|
-
|
|
105
|
-
if (fs_1.
|
|
106
|
-
const fileContents = fs_1.
|
|
115
|
+
for (const codeFile of lines) {
|
|
116
|
+
if (await fs_1.promises?.stat(codeFile).then(stat => stat.isFile()).catch(() => false)) {
|
|
117
|
+
const fileContents = await fs_1.promises.readFile(codeFile, 'utf-8');
|
|
107
118
|
context.push(`### **Contents of ${codeFile}**\n\n${fileContents}\n\n### **End of ${codeFile}**`);
|
|
108
119
|
}
|
|
109
|
-
}
|
|
120
|
+
}
|
|
110
121
|
// Generate the message for unit test creation
|
|
111
122
|
let analysis = '';
|
|
112
123
|
if ((files || []).length > 0) {
|
|
113
124
|
const message = `please create unit tests for these files:
|
|
114
125
|
|
|
115
126
|
## begin list of files
|
|
116
|
-
${(files || []).join(
|
|
127
|
+
${(files || []).join('\n')}
|
|
117
128
|
## end list of files
|
|
118
129
|
|
|
119
130
|
## context
|
|
120
|
-
${context.join(
|
|
131
|
+
${context.join('\n\n')}`;
|
|
121
132
|
// Get the model and analysis using ClovingGPT
|
|
122
133
|
analysis = await gpt.generateText({ prompt: message });
|
|
123
134
|
}
|
|
@@ -130,7 +141,7 @@ ${await (0, git_utils_1.getGitDiff)()}
|
|
|
130
141
|
|
|
131
142
|
## context
|
|
132
143
|
|
|
133
|
-
${context.join(
|
|
144
|
+
${context.join('\n\n')}`;
|
|
134
145
|
// Get the model and analysis using ClovingGPT
|
|
135
146
|
analysis = await gpt.generateText({ prompt: message });
|
|
136
147
|
}
|