cloving 0.1.0 → 0.1.1-8.1

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.
@@ -3,33 +3,46 @@ 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 = __importDefault(require("fs"));
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"));
12
- // Function to estimate token count
13
- const estimateTokens = async (text) => {
14
- const charCount = text.length;
15
- const tokenCount = Math.ceil(charCount / 4);
16
- return tokenCount;
10
+ const config_utils_1 = require("../utils/config_utils");
11
+ const extractChangedFiles = (gitDiff) => {
12
+ const fileRegex = /diff --git a\/(.+?) b\/(.+?)\n/g;
13
+ const files = new Set();
14
+ let match;
15
+ while ((match = fileRegex.exec(gitDiff)) !== null) {
16
+ files.add(match[1]);
17
+ }
18
+ return Array.from(files);
17
19
  };
18
- // Main function for the unit_tests command
19
- const unitTests = async (options) => {
20
- const gpt = new cloving_gpt_1.default(options);
21
- // Generate a temporary file path
22
- const tempFilePath = path_1.default.join(os_1.default.tmpdir(), `unit_tests_${Date.now()}.tmp`);
23
- try {
24
- // Generate the prompt for the AI chat model
25
- const gitDiff = await (0, git_utils_1.getGitDiff)();
26
- const modelFiles = (0, child_process_1.execFileSync)('find', ['app/models', '-type', 'f']).toString().trim();
27
- const testFiles = (0, child_process_1.execFileSync)('find', ['spec', '-type', 'f']).toString().trim();
28
- const prompt = `Here is a list of all my model files:
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
+ };
32
+ const generatePrompt = (files, srcFiles, testFiles, gitDiff) => {
33
+ const filesList = files.length > 0 ? files.join('\n') : 'No files provided';
34
+ const diffSection = gitDiff ? `Here is my git diff:\n\n==== begin git diff ====\n${gitDiff}\n==== end git diff ====\n` : '';
35
+ return `Here is a list of code files I want to generate unit tests for:
36
+
37
+ ==== begin list of files ====
38
+ ${filesList}
39
+ ==== end list of files ====
29
40
 
30
- ==== begin list of models ====
31
- ${modelFiles}
32
- ==== end list of models ====
41
+ Here is a list of all my source files:
42
+
43
+ ==== begin list of source files ====
44
+ ${srcFiles}
45
+ ==== end list of source files ====
33
46
 
34
47
  Here is a list of all my test files:
35
48
 
@@ -37,12 +50,11 @@ Here is a list of all my test files:
37
50
  ${testFiles}
38
51
  ==== end list of test files ====
39
52
 
40
- Please enumerate all the files in this git diff as well as the file names of any models that
41
- this code interacts with. Also, list any test files that might be relevant to these changes:
53
+ ${diffSection}
54
+
55
+ Please enumerate all the files in the provided list${gitDiff ? ' and git diff' : ''} as well as the file names of anything that these files interact with.
42
56
 
43
- ==== begin git diff ====
44
- ${gitDiff}
45
- ==== end git diff ====
57
+ Also, list any test files that might be relevant to these files.
46
58
 
47
59
  Give me this output format for your answer:
48
60
 
@@ -51,69 +63,88 @@ Give me this output format for your answer:
51
63
  app/models/foo.rb
52
64
  app/views/baz/bar.html.erb
53
65
 
54
- ## interacted models
55
-
56
- app/models/pop.rb
57
-
58
66
  ## relevant test files
59
67
 
60
68
  test/models/foo_test.rb
61
69
  test/controllers/baz_controller_test.rb`;
62
- // Estimate and print token count
63
- let tokenCount = await estimateTokens(prompt);
64
- console.log(`Estimated token count: ${tokenCount}`);
65
- // Instantiate ClovingGPT and get the AI chat response
66
- const gpt = new cloving_gpt_1.default();
67
- const aiChatResponse = await gpt.generateText({ prompt });
68
- fs_1.default.writeFileSync(tempFilePath, aiChatResponse);
69
- // Handle "files" argument
70
- if (process.argv.includes('files')) {
71
- console.log(aiChatResponse);
72
- fs_1.default.unlinkSync(tempFilePath);
73
- process.exit(0);
70
+ };
71
+ const unitTests = async (options) => {
72
+ const { files } = options;
73
+ const gpt = new cloving_gpt_1.default(options);
74
+ // Read the cloving.json file
75
+ const config = (0, config_utils_1.readClovingConfig)();
76
+ const testingDirectory = config.testingFrameworks?.find((framework) => framework.directory)?.directory;
77
+ if (!testingDirectory) {
78
+ await setupTestingPrompt(gpt, config);
79
+ }
80
+ let allSrcFiles = [];
81
+ // Collect srcFiles for each language with specified directory and extension
82
+ for (const language of config.languages) {
83
+ if (language.directory && language.extension) {
84
+ const srcFiles = (0, child_process_1.execFileSync)('find', [language.directory, '-type', 'f', '-name', `*${language.extension}`]).toString().trim().split('\n');
85
+ allSrcFiles = allSrcFiles.concat(srcFiles);
86
+ }
87
+ }
88
+ // Ensure allSrcFiles is unique
89
+ allSrcFiles = Array.from(new Set(allSrcFiles));
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.');
92
+ process.exit(1);
93
+ }
94
+ const testFiles = (0, child_process_1.execFileSync)('find', [testingDirectory, '-type', 'f']).toString().trim();
95
+ let contextFiles;
96
+ if (files) {
97
+ const prompt = generatePrompt(files, allSrcFiles.join('\n'), testFiles);
98
+ contextFiles = await gpt.generateText({ prompt });
99
+ }
100
+ else {
101
+ const gitDiff = await (0, git_utils_1.getGitDiff)();
102
+ const changedFiles = extractChangedFiles(gitDiff);
103
+ const prompt = generatePrompt(changedFiles, allSrcFiles.join('\n'), testFiles, gitDiff);
104
+ contextFiles = await gpt.generateText({ prompt });
105
+ }
106
+ // Initialize variables
107
+ const lines = [];
108
+ const context = [];
109
+ // Read input from temporary file
110
+ contextFiles.split('\n').forEach((line) => {
111
+ if (line.trim()) {
112
+ lines.push(line.trim());
74
113
  }
75
- // Initialize variables
76
- const lines = [];
77
- // Read input from temporary file
78
- const fileContent = fs_1.default.readFileSync(tempFilePath, 'utf-8');
79
- fileContent.split('\n').forEach((line) => {
80
- if (line.trim()) {
81
- lines.push(line.trim());
82
- }
83
- });
84
- // Generate output
85
- fs_1.default.writeFileSync(tempFilePath, '## files\n\n');
86
- lines.forEach((line) => {
87
- if (fs_1.default.existsSync(line) && fs_1.default.statSync(line).isFile()) {
88
- const fileContents = fs_1.default.readFileSync(line, 'utf-8');
89
- fs_1.default.appendFileSync(tempFilePath, `### **Contents of ${line}**\n\n${fileContents}\n\n`);
90
- }
91
- });
92
- // Handle "code" argument
93
- if (process.argv.includes('code')) {
94
- console.log(fs_1.default.readFileSync(tempFilePath, 'utf-8'));
95
- fs_1.default.unlinkSync(tempFilePath);
96
- process.exit(0);
114
+ });
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');
118
+ context.push(`### **Contents of ${codeFile}**\n\n${fileContents}\n\n### **End of ${codeFile}**`);
97
119
  }
98
- // Generate the message for unit test creation
120
+ }
121
+ // Generate the message for unit test creation
122
+ let analysis = '';
123
+ if ((files || []).length > 0) {
124
+ const message = `please create unit tests for these files:
125
+
126
+ ## begin list of files
127
+ ${(files || []).join('\n')}
128
+ ## end list of files
129
+
130
+ ## context
131
+ ${context.join('\n\n')}`;
132
+ // Get the model and analysis using ClovingGPT
133
+ analysis = await gpt.generateText({ prompt: message });
134
+ }
135
+ else {
99
136
  const message = `please create unit tests for these changes:
100
137
 
138
+ ## begin diff
101
139
  ${await (0, git_utils_1.getGitDiff)()}
140
+ ## end diff
102
141
 
103
142
  ## context
104
143
 
105
- ${fs_1.default.readFileSync(tempFilePath, 'utf-8')}`;
106
- tokenCount = await estimateTokens(message);
107
- console.log(`Estimated token count: ${tokenCount}`);
108
- // Clean up
109
- fs_1.default.unlinkSync(tempFilePath);
144
+ ${context.join('\n\n')}`;
110
145
  // Get the model and analysis using ClovingGPT
111
- const analysis = await gpt.generateText({ prompt: message });
112
- // Print the output
113
- console.log(analysis);
114
- }
115
- catch (error) {
116
- console.error('Error processing unit tests:', error.message);
146
+ analysis = await gpt.generateText({ prompt: message });
117
147
  }
148
+ console.log(analysis);
118
149
  };
119
150
  exports.default = unitTests;
package/dist/index.js CHANGED
@@ -5,43 +5,133 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const commander_1 = require("commander");
8
- const commit_1 = __importDefault(require("./commands/commit"));
9
- const unit_tests_1 = __importDefault(require("./commands/unit_tests"));
10
- const review_1 = __importDefault(require("./commands/review"));
11
- const init_1 = __importDefault(require("./commands/init"));
8
+ const fs_1 = require("fs");
9
+ const path_1 = require("path");
12
10
  const config_1 = __importDefault(require("./commands/config"));
11
+ const init_1 = __importDefault(require("./commands/init"));
13
12
  const models_1 = __importDefault(require("./commands/models"));
13
+ const shell_1 = __importDefault(require("./commands/generate/shell"));
14
+ const code_1 = __importDefault(require("./commands/generate/code"));
15
+ const commit_1 = __importDefault(require("./commands/generate/commit"));
16
+ const context_1 = __importDefault(require("./commands/generate/context"));
17
+ const unit_tests_1 = __importDefault(require("./commands/generate/unit_tests"));
18
+ const review_1 = __importDefault(require("./commands/generate/review"));
19
+ const init_2 = __importDefault(require("./commands/project/init"));
20
+ const plan_1 = __importDefault(require("./commands/project/plan"));
21
+ const build_1 = __importDefault(require("./commands/project/build"));
22
+ const complete_1 = __importDefault(require("./commands/project/complete"));
23
+ // Function to get version from package.json
24
+ const getPackageVersion = () => {
25
+ const packagePath = (0, path_1.join)(__dirname, 'package.json');
26
+ const packageJson = JSON.parse((0, fs_1.readFileSync)(packagePath, 'utf8'));
27
+ return packageJson.version;
28
+ };
14
29
  const program = new commander_1.Command();
15
30
  program
16
31
  .name('cloving')
17
32
  .description('Integrate AI into your development workflow for generating commit messages, code reviews, and unit tests.')
18
- .version('1.0.0');
33
+ .version(getPackageVersion());
19
34
  program
20
- .command('commit')
21
- .description('Generate a commit message and commit the changes')
22
- .option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
23
- .action(commit_1.default);
35
+ .command('config')
36
+ .description('Configure cloving with your API key and models to use')
37
+ .action(config_1.default);
24
38
  program
25
- .command('unit-tests')
26
- .description('Generate unit tests for the changes')
39
+ .command('init')
40
+ .description('Setup cloving in the current directory')
27
41
  .option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
28
- .action(unit_tests_1.default);
42
+ .option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)')
43
+ .action(init_1.default);
29
44
  program
30
45
  .command('models')
46
+ .alias('m')
31
47
  .description('List available models')
32
48
  .action(models_1.default);
33
49
  program
50
+ .command('commit')
51
+ .alias('c')
52
+ .description('Alias for cloving generate commit')
53
+ .option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
54
+ .option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)')
55
+ .action(commit_1.default);
56
+ // Generate commands
57
+ const generate = program
58
+ .command('generate')
59
+ .alias('g')
60
+ .description('Generate various items like unit-tests and code reviews');
61
+ generate
62
+ .command('shell')
63
+ .alias('sh')
64
+ .description('Generate a shell command based on a prompt')
65
+ .option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
66
+ .option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)')
67
+ .option('-p, --prompt <prompt>', 'Specify the prompt to use')
68
+ .option('-t, --temperature <temperature>', 'Temperature for the model (default 0.2)')
69
+ .action(shell_1.default);
70
+ generate
71
+ .command('code')
72
+ .alias('c')
73
+ .description('Generate code based on a prompt')
74
+ .option('--save', 'Automatically save all files after generating the code')
75
+ .option('-i, --interactive', 'Auto-save generated code and then show a new prompt with existing context to revise the code further')
76
+ .option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
77
+ .option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5:sonnet-20240620)')
78
+ .option('-t, --temperature <temperature>', 'Temperature for the model (default 0.2)')
79
+ .option('-p, --prompt <prompt>', 'Specify the prompt to use')
80
+ .option('-f, --files <filenames...>', 'Specify filenames of files with context to use for generating code')
81
+ .action(code_1.default);
82
+ generate
83
+ .command('commit')
84
+ .description('Generate a commit message and commit the changes')
85
+ .option('-t, --temperature <temperature>', 'Temperature for the model (default 0.2)')
86
+ .option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
87
+ .option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)')
88
+ .action(commit_1.default);
89
+ generate
90
+ .command('context')
91
+ .description('Create a context string for generating code')
92
+ .option('-f, --files <filenames...>', 'Specify filenames of files with context')
93
+ .action(context_1.default);
94
+ generate
95
+ .command('unit-tests')
96
+ .alias('u')
97
+ .description('Generate unit tests (if you don\'t specify filenames, it will generate tests for commited changes that differ from the main/master branch)')
98
+ .option('--save', 'Automatically save all files after generating the unit tests')
99
+ .option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
100
+ .option('-f, --files <filenames...>', 'Specify filenames for the unit tests')
101
+ .option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)')
102
+ .option('-t, --temperature <temperature>', 'Temperature for the model (default 0.2)')
103
+ .action(unit_tests_1.default);
104
+ generate
34
105
  .command('review')
35
- .description('Review the changes and propose ')
106
+ .alias('r')
107
+ .description('Review the code for commited changes that differ from the main/master branch')
36
108
  .option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
109
+ .option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)')
110
+ .option('-t, --temperature <temperature>', 'Temperature for the model (default 0.2)')
37
111
  .action(review_1.default);
38
- program
112
+ // Project commands
113
+ const project = program
114
+ .command('project')
115
+ .alias('p')
116
+ .description('Commands for cloving a project');
117
+ project
39
118
  .command('init')
40
- .description('Setup cloving in the current project')
41
- .option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
42
- .action(init_1.default);
43
- program
44
- .command('config')
45
- .description('Configure cloving with your API key and model')
46
- .action(config_1.default);
119
+ .alias('i')
120
+ .description('Setup a new cloving project inside a git branch')
121
+ .action(init_2.default);
122
+ project
123
+ .command('plan')
124
+ .alias('p')
125
+ .description('Plan the steps to complete the project')
126
+ .action(plan_1.default);
127
+ project
128
+ .command('build')
129
+ .alias('b')
130
+ .description('Generate code to build the project')
131
+ .action(build_1.default);
132
+ project
133
+ .command('complete')
134
+ .alias('c')
135
+ .description('Clean up and finalize the project')
136
+ .action(complete_1.default);
47
137
  program.parse(process.argv);
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "cloving",
3
+ "version": "0.1.18",
4
+ "packageManager": "yarn@1.22.22",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc && cp package.json dist/package.json",
9
+ "start": "node dist/index.js",
10
+ "watch": "tsc -w",
11
+ "check": "bash -c 'npx tsc --noEmit --skipLibCheck'",
12
+ "test": "bash -c jest",
13
+ "prepare": "husky"
14
+ },
15
+ "bin": "./dist/index.js",
16
+ "files": [
17
+ "dist",
18
+ "!**/test/**"
19
+ ],
20
+ "keywords": [],
21
+ "author": "Lucas Carlson",
22
+ "license": "MIT",
23
+ "description": "",
24
+ "lint-staged": {
25
+ "*.ts": [
26
+ "yarn run check"
27
+ ]
28
+ },
29
+ "lint-prepush": {
30
+ "base": "main",
31
+ "tasks": {
32
+ "*.ts": [
33
+ "yarn run check",
34
+ "yarn run test"
35
+ ]
36
+ }
37
+ },
38
+ "dependencies": {
39
+ "@inquirer/prompts": "^5.3.6",
40
+ "axios": "^1.7.3",
41
+ "cli-highlight": "^2.1.11",
42
+ "commander": "^12.1.0",
43
+ "copy-paste": "^1.5.3",
44
+ "eslint": "^9.8.0",
45
+ "eslint-config-prettier": "^9.1.0",
46
+ "eslint-config-raine": "^0.5.0",
47
+ "eslint-config-standard": "^17.1.0",
48
+ "eslint-plugin-import": "^2.29.1",
49
+ "eslint-plugin-jsdoc": "^48.11.0",
50
+ "eslint-plugin-n": "^17.10.1",
51
+ "eslint-plugin-promise": "^7.0.0",
52
+ "ignore": "^5.3.1",
53
+ "ini": "^4.1.3",
54
+ "nock": "^13.5.4",
55
+ "vite": "^5.3.5",
56
+ "vite-node": "^2.0.5"
57
+ },
58
+ "devDependencies": {
59
+ "@types/copy-paste": "^1.1.33",
60
+ "@types/ini": "^4.1.1",
61
+ "@types/inquirer": "^9.0.7",
62
+ "@types/jest": "^29.5.12",
63
+ "@types/node": "^22.1.0",
64
+ "husky": "^9.1.4",
65
+ "jest": "^29.7.0",
66
+ "lint-prepush": "^2.2.2",
67
+ "lint-staged": "^15.2.8",
68
+ "ts-jest": "^29.2.4",
69
+ "typescript": "^5.5.4"
70
+ },
71
+ "resolutions": {
72
+ "eslint": "8.57.0",
73
+ "eslint-plugin-n": "16.6.2",
74
+ "eslint-plugin-import": "2.29.1"
75
+ }
76
+ }
@@ -3,44 +3,17 @@ 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
- exports.getConfig = exports.saveConfig = exports.fetchModels = exports.promptUser = exports.runCommand = exports.generateFileList = exports.checkForSpecialFiles = exports.collectSpecialFileContents = exports.SPECIAL_FILES = exports.CONFIG_PATH = void 0;
6
+ exports.addFileOrDirectoryToContext = exports.readFileContent = exports.fetchModels = exports.runCommand = exports.generateFileList = exports.checkForSpecialFiles = exports.collectSpecialFileContents = exports.SPECIAL_FILES = void 0;
7
7
  const child_process_1 = require("child_process");
8
- const readline_1 = __importDefault(require("readline"));
9
8
  const fs_1 = __importDefault(require("fs"));
10
- const os_1 = __importDefault(require("os"));
11
9
  const path_1 = __importDefault(require("path"));
12
- exports.CONFIG_PATH = path_1.default.join(os_1.default.homedir(), '.cloving.json');
10
+ const config_utils_1 = require("./config_utils");
13
11
  exports.SPECIAL_FILES = [
14
- 'package.json',
15
- 'Gemfile',
16
- 'requirements.txt',
17
- 'Pipfile',
18
- 'pyproject.toml',
19
- 'pom.xml',
20
- 'build.gradle',
21
- '.csproj',
22
- 'packages.config',
23
- 'composer.json',
24
- 'CMakeLists.txt',
25
- 'conanfile.txt',
26
- 'conanfile.py',
27
- 'go.mod',
28
- 'Cargo.toml',
29
- 'Package.swift',
30
- 'build.gradle.kts',
31
- 'Podfile',
32
- 'Cartfile',
33
- 'cpanfile',
34
- 'DESCRIPTION',
35
- 'mix.exs',
36
- 'build.sbt',
37
- 'pubspec.yaml',
38
- 'stack.yaml',
39
- 'cabal.project',
40
- 'Project.toml',
41
- 'rockspec',
42
- 'rebar.config',
43
- 'project.clj'
12
+ 'package.json', 'Gemfile', 'requirements.txt', 'Pipfile', 'pyproject.toml', 'pom.xml', 'build.gradle',
13
+ '.csproj', 'packages.config', 'composer.json', 'CMakeLists.txt', 'conanfile.txt', 'conanfile.py',
14
+ 'go.mod', 'Cargo.toml', 'Package.swift', 'build.gradle.kts', 'Podfile', 'Cartfile', 'cpanfile',
15
+ 'DESCRIPTION', 'mix.exs', 'build.sbt', 'pubspec.yaml', 'stack.yaml', 'cabal.project', 'Project.toml',
16
+ 'rockspec', 'rebar.config', 'project.clj'
44
17
  ];
45
18
  const collectSpecialFileContents = () => {
46
19
  const specialFileContents = {};
@@ -58,9 +31,7 @@ const collectSpecialFileContents = () => {
58
31
  return specialFileContents;
59
32
  };
60
33
  exports.collectSpecialFileContents = collectSpecialFileContents;
61
- const checkForSpecialFiles = () => {
62
- return exports.SPECIAL_FILES.some(file => fs_1.default.existsSync(file));
63
- };
34
+ const checkForSpecialFiles = () => exports.SPECIAL_FILES.some(file => fs_1.default.existsSync(file));
64
35
  exports.checkForSpecialFiles = checkForSpecialFiles;
65
36
  const generateFileList = async () => {
66
37
  try {
@@ -98,19 +69,6 @@ const runCommand = (command, args) => {
98
69
  });
99
70
  };
100
71
  exports.runCommand = runCommand;
101
- const promptUser = (question) => {
102
- const rl = readline_1.default.createInterface({
103
- input: process.stdin,
104
- output: process.stdout
105
- });
106
- return new Promise((resolve) => {
107
- rl.question(question, (answer) => {
108
- rl.close();
109
- resolve(answer.trim());
110
- });
111
- });
112
- };
113
- exports.promptUser = promptUser;
114
72
  const fetchModels = async () => {
115
73
  try {
116
74
  const modelsOutput = await (0, exports.runCommand)('cloving', ['models']);
@@ -122,30 +80,38 @@ const fetchModels = async () => {
122
80
  }
123
81
  };
124
82
  exports.fetchModels = fetchModels;
125
- const saveConfig = (config) => {
126
- fs_1.default.writeFileSync(exports.CONFIG_PATH, JSON.stringify(config, null, 2));
127
- console.log(`Configuration saved to ${exports.CONFIG_PATH}`);
128
- };
129
- exports.saveConfig = saveConfig;
130
- const getConfig = () => {
83
+ const readFileContent = (file) => {
131
84
  try {
132
- if (fs_1.default.existsSync(exports.CONFIG_PATH)) {
133
- const rawConfig = fs_1.default.readFileSync(exports.CONFIG_PATH, 'utf-8');
134
- return JSON.parse(rawConfig);
135
- }
85
+ return fs_1.default.readFileSync(file, 'utf-8');
86
+ }
87
+ catch (error) {
88
+ console.error('Error reading file content:', error.message);
89
+ return '';
136
90
  }
137
- catch (err) {
138
- console.error('Error reading configuration:', err);
91
+ };
92
+ exports.readFileContent = readFileContent;
93
+ const addFileOrDirectoryToContext = async (contextFile, contextFiles, options) => {
94
+ const filePath = path_1.default.resolve(contextFile);
95
+ if (await fs_1.default.promises.stat(filePath).then(stat => stat.isDirectory()).catch(() => false)) {
96
+ // Add all files in the specified directory
97
+ const files = await (0, config_utils_1.getAllFiles)(options, false);
98
+ for (const file of files) {
99
+ // if the file is in the same directory as the context file, add it to the context
100
+ if (path_1.default.dirname(file) === path_1.default.dirname(filePath)) {
101
+ const content = await fs_1.default.promises.readFile(file, 'utf-8');
102
+ contextFiles[path_1.default.relative(process.cwd(), file)] = content;
103
+ }
104
+ }
105
+ console.log(`Added contents of ${contextFile} to context.`);
139
106
  }
140
- if (process.env.CLOVING_MODEL) {
141
- return {
142
- models: { [`${process.env.CLOVING_MODEL}`]: process.env.CLOVING_API_KEY ?? '' },
143
- primaryModel: process.env.CLOVING_MODEL,
144
- silent: false
145
- };
107
+ else if (await fs_1.default.promises.stat(filePath).then(stat => stat.isFile()).catch(() => false)) {
108
+ const content = await fs_1.default.promises.readFile(filePath, 'utf-8');
109
+ contextFiles[contextFile] = content;
110
+ console.log(`Added ${filePath} to context.`);
146
111
  }
147
112
  else {
148
- return { models: {}, primaryModel: null, silent: false };
113
+ console.log(`File or directory ${contextFile} does not exist.`);
149
114
  }
115
+ return contextFiles;
150
116
  };
151
- exports.getConfig = getConfig;
117
+ exports.addFileOrDirectoryToContext = addFileOrDirectoryToContext;