├── .gitignore ├── README.md ├── example.env ├── package-lock.json ├── package.json └── src ├── agents └── agent1.txt ├── index.js └── modules ├── action.js ├── answer.js ├── init.js └── init ├── askForTask.js ├── askForWorkingDir.js ├── parametrizeAgent.js └── parseDir.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | 21 | # debug 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | 26 | # env files 27 | .env 28 | .env.local 29 | .env.development.local 30 | .env.test.local 31 | .env.production.local 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoCoderV1 2 | 3 | Welcome to **AutoCoderV1**! This is an early-stage project aimed at creating an intelligent programming assistant that makes code analysis and modification a breeze. With the power of AI, we hope to bring the expertise of senior programmers right to your terminal. 4 | 5 | Although the project is in its early stages, we believe in its potential and would like to invite you to contribute to its development. We're excited to see where the community can take AutoCoderV1 and how it will evolve over time. 6 | 7 | # 19/04/2023 update 8 | 9 | There is now a second git branch `agent2` with a simplified agent that uses python to achieve tasks. Feel free to experiment with it! 10 | 11 | ## Features 12 | 13 | - Analyze file structures and files 14 | - Create, update, or delete files according to given tasks 15 | - Ask for user feedback and additional information 16 | - Provide suggestions on how to improve the code 17 | 18 | ## Getting Started 19 | 20 | To get started with AutoCoderV1, simply clone the repository and follow the installation instructions below. 21 | 22 | ### Prerequisites 23 | 24 | Make sure you have Node.js and npm installed on your system. 25 | 26 | ### Installation 27 | 28 | 1. Clone the repository 29 | 2. Install dependencies `npm install` 30 | 3. Copy `example.env` to `.env` 31 | 4. Update your OpenAI api key 32 | 5. Youu may want to either switch mode or parametrize 33 | 6. Run the application `npm start` 34 | 35 | ## Contributing 36 | 37 | We're actively seeking contributors to help us improve and expand AutoCoderV1. If you're interested, we'd love to hear your suggestions and ideas. 38 | 39 | Feel free to open issues, submit pull requests, or just share your thoughts. Every bit of feedback and contribution is valuable in making this project even better. 40 | 41 | ## License 42 | 43 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 44 | 45 | ## Acknowledgments 46 | 47 | - Thanks to the OpenAI team for providing the foundation for the AI capabilities of AutoCoderV1 48 | - A special shout-out to all future contributors who will help shape the future of this project 49 | 50 | --- 51 | 52 | Happy coding! Let's work together to create a tool that revolutionizes the way we write, analyze, and improve code. 53 | 54 | -------------------------------------------------------------------------------- /example.env: -------------------------------------------------------------------------------- 1 | # Do not share your OpenAI API key with anyone! It should remain a secret. 2 | OPENAI_API_KEY=Your OpenAI Api Key 3 | AGENT='agents/agent1.txt' 4 | MODE='params' #two modes 'env' and 'params' THIS IS TODO 5 | 6 | 7 | # TODO 8 | # if MODE='params' than the following will not be used, instead will be prompted for: 9 | 10 | WORK_ON_DIRECTORY='C:\code\tryouts\purehtml' 11 | FIRST_TASK='Change the title inside index.html to "My test title"' -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "autocoderv1node", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "autocoderv1node", 9 | "version": "1.0.0", 10 | "license": "MIT", 11 | "dependencies": { 12 | "dotenv": "^16.0.3", 13 | "ignore": "^5.2.4", 14 | "inquirer": "^9.1.5", 15 | "klaw-sync": "^6.0.0", 16 | "openai": "^3.2.1" 17 | } 18 | }, 19 | "node_modules/ansi-escapes": { 20 | "version": "6.1.0", 21 | "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-6.1.0.tgz", 22 | "integrity": "sha512-bQyg9bzRntwR/8b89DOEhGwctcwCrbWW/TuqTQnpqpy5Fz3aovcOTj5i8NJV6AHc8OGNdMaqdxAWww8pz2kiKg==", 23 | "dependencies": { 24 | "type-fest": "^3.0.0" 25 | }, 26 | "engines": { 27 | "node": ">=14.16" 28 | }, 29 | "funding": { 30 | "url": "https://github.com/sponsors/sindresorhus" 31 | } 32 | }, 33 | "node_modules/ansi-regex": { 34 | "version": "6.0.1", 35 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", 36 | "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", 37 | "engines": { 38 | "node": ">=12" 39 | }, 40 | "funding": { 41 | "url": "https://github.com/chalk/ansi-regex?sponsor=1" 42 | } 43 | }, 44 | "node_modules/ansi-styles": { 45 | "version": "6.2.1", 46 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", 47 | "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", 48 | "engines": { 49 | "node": ">=12" 50 | }, 51 | "funding": { 52 | "url": "https://github.com/chalk/ansi-styles?sponsor=1" 53 | } 54 | }, 55 | "node_modules/asynckit": { 56 | "version": "0.4.0", 57 | "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", 58 | "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" 59 | }, 60 | "node_modules/axios": { 61 | "version": "0.26.1", 62 | "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", 63 | "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==", 64 | "dependencies": { 65 | "follow-redirects": "^1.14.8" 66 | } 67 | }, 68 | "node_modules/base64-js": { 69 | "version": "1.5.1", 70 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", 71 | "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", 72 | "funding": [ 73 | { 74 | "type": "github", 75 | "url": "https://github.com/sponsors/feross" 76 | }, 77 | { 78 | "type": "patreon", 79 | "url": "https://www.patreon.com/feross" 80 | }, 81 | { 82 | "type": "consulting", 83 | "url": "https://feross.org/support" 84 | } 85 | ] 86 | }, 87 | "node_modules/bl": { 88 | "version": "5.1.0", 89 | "resolved": "https://registry.npmjs.org/bl/-/bl-5.1.0.tgz", 90 | "integrity": "sha512-tv1ZJHLfTDnXE6tMHv73YgSJaWR2AFuPwMntBe7XL/GBFHnT0CLnsHMogfk5+GzCDC5ZWarSCYaIGATZt9dNsQ==", 91 | "dependencies": { 92 | "buffer": "^6.0.3", 93 | "inherits": "^2.0.4", 94 | "readable-stream": "^3.4.0" 95 | } 96 | }, 97 | "node_modules/buffer": { 98 | "version": "6.0.3", 99 | "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", 100 | "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", 101 | "funding": [ 102 | { 103 | "type": "github", 104 | "url": "https://github.com/sponsors/feross" 105 | }, 106 | { 107 | "type": "patreon", 108 | "url": "https://www.patreon.com/feross" 109 | }, 110 | { 111 | "type": "consulting", 112 | "url": "https://feross.org/support" 113 | } 114 | ], 115 | "dependencies": { 116 | "base64-js": "^1.3.1", 117 | "ieee754": "^1.2.1" 118 | } 119 | }, 120 | "node_modules/chalk": { 121 | "version": "5.2.0", 122 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.2.0.tgz", 123 | "integrity": "sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==", 124 | "engines": { 125 | "node": "^12.17.0 || ^14.13 || >=16.0.0" 126 | }, 127 | "funding": { 128 | "url": "https://github.com/chalk/chalk?sponsor=1" 129 | } 130 | }, 131 | "node_modules/chardet": { 132 | "version": "0.7.0", 133 | "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", 134 | "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==" 135 | }, 136 | "node_modules/cli-cursor": { 137 | "version": "4.0.0", 138 | "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", 139 | "integrity": "sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==", 140 | "dependencies": { 141 | "restore-cursor": "^4.0.0" 142 | }, 143 | "engines": { 144 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 145 | }, 146 | "funding": { 147 | "url": "https://github.com/sponsors/sindresorhus" 148 | } 149 | }, 150 | "node_modules/cli-spinners": { 151 | "version": "2.8.0", 152 | "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.8.0.tgz", 153 | "integrity": "sha512-/eG5sJcvEIwxcdYM86k5tPwn0MUzkX5YY3eImTGpJOZgVe4SdTMY14vQpcxgBzJ0wXwAYrS8E+c3uHeK4JNyzQ==", 154 | "engines": { 155 | "node": ">=6" 156 | }, 157 | "funding": { 158 | "url": "https://github.com/sponsors/sindresorhus" 159 | } 160 | }, 161 | "node_modules/cli-width": { 162 | "version": "4.0.0", 163 | "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-4.0.0.tgz", 164 | "integrity": "sha512-ZksGS2xpa/bYkNzN3BAw1wEjsLV/ZKOf/CCrJ/QOBsxx6fOARIkwTutxp1XIOIohi6HKmOFjMoK/XaqDVUpEEw==", 165 | "engines": { 166 | "node": ">= 12" 167 | } 168 | }, 169 | "node_modules/clone": { 170 | "version": "1.0.4", 171 | "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", 172 | "integrity": "sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==", 173 | "engines": { 174 | "node": ">=0.8" 175 | } 176 | }, 177 | "node_modules/combined-stream": { 178 | "version": "1.0.8", 179 | "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", 180 | "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", 181 | "dependencies": { 182 | "delayed-stream": "~1.0.0" 183 | }, 184 | "engines": { 185 | "node": ">= 0.8" 186 | } 187 | }, 188 | "node_modules/defaults": { 189 | "version": "1.0.4", 190 | "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.4.tgz", 191 | "integrity": "sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==", 192 | "dependencies": { 193 | "clone": "^1.0.2" 194 | }, 195 | "funding": { 196 | "url": "https://github.com/sponsors/sindresorhus" 197 | } 198 | }, 199 | "node_modules/delayed-stream": { 200 | "version": "1.0.0", 201 | "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", 202 | "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", 203 | "engines": { 204 | "node": ">=0.4.0" 205 | } 206 | }, 207 | "node_modules/dotenv": { 208 | "version": "16.0.3", 209 | "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", 210 | "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", 211 | "engines": { 212 | "node": ">=12" 213 | } 214 | }, 215 | "node_modules/eastasianwidth": { 216 | "version": "0.2.0", 217 | "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", 218 | "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==" 219 | }, 220 | "node_modules/emoji-regex": { 221 | "version": "9.2.2", 222 | "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", 223 | "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==" 224 | }, 225 | "node_modules/escape-string-regexp": { 226 | "version": "5.0.0", 227 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", 228 | "integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==", 229 | "engines": { 230 | "node": ">=12" 231 | }, 232 | "funding": { 233 | "url": "https://github.com/sponsors/sindresorhus" 234 | } 235 | }, 236 | "node_modules/external-editor": { 237 | "version": "3.1.0", 238 | "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz", 239 | "integrity": "sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==", 240 | "dependencies": { 241 | "chardet": "^0.7.0", 242 | "iconv-lite": "^0.4.24", 243 | "tmp": "^0.0.33" 244 | }, 245 | "engines": { 246 | "node": ">=4" 247 | } 248 | }, 249 | "node_modules/figures": { 250 | "version": "5.0.0", 251 | "resolved": "https://registry.npmjs.org/figures/-/figures-5.0.0.tgz", 252 | "integrity": "sha512-ej8ksPF4x6e5wvK9yevct0UCXh8TTFlWGVLlgjZuoBH1HwjIfKE/IdL5mq89sFA7zELi1VhKpmtDnrs7zWyeyg==", 253 | "dependencies": { 254 | "escape-string-regexp": "^5.0.0", 255 | "is-unicode-supported": "^1.2.0" 256 | }, 257 | "engines": { 258 | "node": ">=14" 259 | }, 260 | "funding": { 261 | "url": "https://github.com/sponsors/sindresorhus" 262 | } 263 | }, 264 | "node_modules/follow-redirects": { 265 | "version": "1.15.2", 266 | "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", 267 | "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", 268 | "funding": [ 269 | { 270 | "type": "individual", 271 | "url": "https://github.com/sponsors/RubenVerborgh" 272 | } 273 | ], 274 | "engines": { 275 | "node": ">=4.0" 276 | }, 277 | "peerDependenciesMeta": { 278 | "debug": { 279 | "optional": true 280 | } 281 | } 282 | }, 283 | "node_modules/form-data": { 284 | "version": "4.0.0", 285 | "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", 286 | "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", 287 | "dependencies": { 288 | "asynckit": "^0.4.0", 289 | "combined-stream": "^1.0.8", 290 | "mime-types": "^2.1.12" 291 | }, 292 | "engines": { 293 | "node": ">= 6" 294 | } 295 | }, 296 | "node_modules/graceful-fs": { 297 | "version": "4.2.11", 298 | "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", 299 | "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" 300 | }, 301 | "node_modules/iconv-lite": { 302 | "version": "0.4.24", 303 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 304 | "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", 305 | "dependencies": { 306 | "safer-buffer": ">= 2.1.2 < 3" 307 | }, 308 | "engines": { 309 | "node": ">=0.10.0" 310 | } 311 | }, 312 | "node_modules/ieee754": { 313 | "version": "1.2.1", 314 | "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", 315 | "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", 316 | "funding": [ 317 | { 318 | "type": "github", 319 | "url": "https://github.com/sponsors/feross" 320 | }, 321 | { 322 | "type": "patreon", 323 | "url": "https://www.patreon.com/feross" 324 | }, 325 | { 326 | "type": "consulting", 327 | "url": "https://feross.org/support" 328 | } 329 | ] 330 | }, 331 | "node_modules/ignore": { 332 | "version": "5.2.4", 333 | "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", 334 | "integrity": "sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==", 335 | "engines": { 336 | "node": ">= 4" 337 | } 338 | }, 339 | "node_modules/inherits": { 340 | "version": "2.0.4", 341 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 342 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 343 | }, 344 | "node_modules/inquirer": { 345 | "version": "9.1.5", 346 | "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-9.1.5.tgz", 347 | "integrity": "sha512-3ygAIh8gcZavV9bj6MTdYddG2zPSYswP808fKS46NOwlF0zZljVpnLCHODDqItWJDbDpLb3aouAxGaJbkxoppA==", 348 | "dependencies": { 349 | "ansi-escapes": "^6.0.0", 350 | "chalk": "^5.2.0", 351 | "cli-cursor": "^4.0.0", 352 | "cli-width": "^4.0.0", 353 | "external-editor": "^3.0.3", 354 | "figures": "^5.0.0", 355 | "lodash": "^4.17.21", 356 | "mute-stream": "1.0.0", 357 | "ora": "^6.1.2", 358 | "run-async": "^2.4.0", 359 | "rxjs": "^7.8.0", 360 | "string-width": "^5.1.2", 361 | "strip-ansi": "^7.0.1", 362 | "through": "^2.3.6", 363 | "wrap-ansi": "^8.1.0" 364 | }, 365 | "engines": { 366 | "node": ">=14.18.0" 367 | } 368 | }, 369 | "node_modules/is-interactive": { 370 | "version": "2.0.0", 371 | "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-2.0.0.tgz", 372 | "integrity": "sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==", 373 | "engines": { 374 | "node": ">=12" 375 | }, 376 | "funding": { 377 | "url": "https://github.com/sponsors/sindresorhus" 378 | } 379 | }, 380 | "node_modules/is-unicode-supported": { 381 | "version": "1.3.0", 382 | "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz", 383 | "integrity": "sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==", 384 | "engines": { 385 | "node": ">=12" 386 | }, 387 | "funding": { 388 | "url": "https://github.com/sponsors/sindresorhus" 389 | } 390 | }, 391 | "node_modules/klaw-sync": { 392 | "version": "6.0.0", 393 | "resolved": "https://registry.npmjs.org/klaw-sync/-/klaw-sync-6.0.0.tgz", 394 | "integrity": "sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==", 395 | "dependencies": { 396 | "graceful-fs": "^4.1.11" 397 | } 398 | }, 399 | "node_modules/lodash": { 400 | "version": "4.17.21", 401 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", 402 | "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" 403 | }, 404 | "node_modules/log-symbols": { 405 | "version": "5.1.0", 406 | "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-5.1.0.tgz", 407 | "integrity": "sha512-l0x2DvrW294C9uDCoQe1VSU4gf529FkSZ6leBl4TiqZH/e+0R7hSfHQBNut2mNygDgHwvYHfFLn6Oxb3VWj2rA==", 408 | "dependencies": { 409 | "chalk": "^5.0.0", 410 | "is-unicode-supported": "^1.1.0" 411 | }, 412 | "engines": { 413 | "node": ">=12" 414 | }, 415 | "funding": { 416 | "url": "https://github.com/sponsors/sindresorhus" 417 | } 418 | }, 419 | "node_modules/mime-db": { 420 | "version": "1.52.0", 421 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", 422 | "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", 423 | "engines": { 424 | "node": ">= 0.6" 425 | } 426 | }, 427 | "node_modules/mime-types": { 428 | "version": "2.1.35", 429 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", 430 | "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", 431 | "dependencies": { 432 | "mime-db": "1.52.0" 433 | }, 434 | "engines": { 435 | "node": ">= 0.6" 436 | } 437 | }, 438 | "node_modules/mimic-fn": { 439 | "version": "2.1.0", 440 | "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", 441 | "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", 442 | "engines": { 443 | "node": ">=6" 444 | } 445 | }, 446 | "node_modules/mute-stream": { 447 | "version": "1.0.0", 448 | "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-1.0.0.tgz", 449 | "integrity": "sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==", 450 | "engines": { 451 | "node": "^14.17.0 || ^16.13.0 || >=18.0.0" 452 | } 453 | }, 454 | "node_modules/onetime": { 455 | "version": "5.1.2", 456 | "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", 457 | "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", 458 | "dependencies": { 459 | "mimic-fn": "^2.1.0" 460 | }, 461 | "engines": { 462 | "node": ">=6" 463 | }, 464 | "funding": { 465 | "url": "https://github.com/sponsors/sindresorhus" 466 | } 467 | }, 468 | "node_modules/openai": { 469 | "version": "3.2.1", 470 | "resolved": "https://registry.npmjs.org/openai/-/openai-3.2.1.tgz", 471 | "integrity": "sha512-762C9BNlJPbjjlWZi4WYK9iM2tAVAv0uUp1UmI34vb0CN5T2mjB/qM6RYBmNKMh/dN9fC+bxqPwWJZUTWW052A==", 472 | "dependencies": { 473 | "axios": "^0.26.0", 474 | "form-data": "^4.0.0" 475 | } 476 | }, 477 | "node_modules/ora": { 478 | "version": "6.3.0", 479 | "resolved": "https://registry.npmjs.org/ora/-/ora-6.3.0.tgz", 480 | "integrity": "sha512-1/D8uRFY0ay2kgBpmAwmSA404w4OoPVhHMqRqtjvrcK/dnzcEZxMJ+V4DUbyICu8IIVRclHcOf5wlD1tMY4GUQ==", 481 | "dependencies": { 482 | "chalk": "^5.0.0", 483 | "cli-cursor": "^4.0.0", 484 | "cli-spinners": "^2.6.1", 485 | "is-interactive": "^2.0.0", 486 | "is-unicode-supported": "^1.1.0", 487 | "log-symbols": "^5.1.0", 488 | "stdin-discarder": "^0.1.0", 489 | "strip-ansi": "^7.0.1", 490 | "wcwidth": "^1.0.1" 491 | }, 492 | "engines": { 493 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 494 | }, 495 | "funding": { 496 | "url": "https://github.com/sponsors/sindresorhus" 497 | } 498 | }, 499 | "node_modules/os-tmpdir": { 500 | "version": "1.0.2", 501 | "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", 502 | "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", 503 | "engines": { 504 | "node": ">=0.10.0" 505 | } 506 | }, 507 | "node_modules/readable-stream": { 508 | "version": "3.6.2", 509 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", 510 | "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", 511 | "dependencies": { 512 | "inherits": "^2.0.3", 513 | "string_decoder": "^1.1.1", 514 | "util-deprecate": "^1.0.1" 515 | }, 516 | "engines": { 517 | "node": ">= 6" 518 | } 519 | }, 520 | "node_modules/restore-cursor": { 521 | "version": "4.0.0", 522 | "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-4.0.0.tgz", 523 | "integrity": "sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==", 524 | "dependencies": { 525 | "onetime": "^5.1.0", 526 | "signal-exit": "^3.0.2" 527 | }, 528 | "engines": { 529 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 530 | }, 531 | "funding": { 532 | "url": "https://github.com/sponsors/sindresorhus" 533 | } 534 | }, 535 | "node_modules/run-async": { 536 | "version": "2.4.1", 537 | "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", 538 | "integrity": "sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==", 539 | "engines": { 540 | "node": ">=0.12.0" 541 | } 542 | }, 543 | "node_modules/rxjs": { 544 | "version": "7.8.0", 545 | "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.0.tgz", 546 | "integrity": "sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==", 547 | "dependencies": { 548 | "tslib": "^2.1.0" 549 | } 550 | }, 551 | "node_modules/safe-buffer": { 552 | "version": "5.2.1", 553 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", 554 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", 555 | "funding": [ 556 | { 557 | "type": "github", 558 | "url": "https://github.com/sponsors/feross" 559 | }, 560 | { 561 | "type": "patreon", 562 | "url": "https://www.patreon.com/feross" 563 | }, 564 | { 565 | "type": "consulting", 566 | "url": "https://feross.org/support" 567 | } 568 | ] 569 | }, 570 | "node_modules/safer-buffer": { 571 | "version": "2.1.2", 572 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 573 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 574 | }, 575 | "node_modules/signal-exit": { 576 | "version": "3.0.7", 577 | "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", 578 | "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" 579 | }, 580 | "node_modules/stdin-discarder": { 581 | "version": "0.1.0", 582 | "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.1.0.tgz", 583 | "integrity": "sha512-xhV7w8S+bUwlPTb4bAOUQhv8/cSS5offJuX8GQGq32ONF0ZtDWKfkdomM3HMRA+LhX6um/FZ0COqlwsjD53LeQ==", 584 | "dependencies": { 585 | "bl": "^5.0.0" 586 | }, 587 | "engines": { 588 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 589 | }, 590 | "funding": { 591 | "url": "https://github.com/sponsors/sindresorhus" 592 | } 593 | }, 594 | "node_modules/string_decoder": { 595 | "version": "1.3.0", 596 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", 597 | "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", 598 | "dependencies": { 599 | "safe-buffer": "~5.2.0" 600 | } 601 | }, 602 | "node_modules/string-width": { 603 | "version": "5.1.2", 604 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", 605 | "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", 606 | "dependencies": { 607 | "eastasianwidth": "^0.2.0", 608 | "emoji-regex": "^9.2.2", 609 | "strip-ansi": "^7.0.1" 610 | }, 611 | "engines": { 612 | "node": ">=12" 613 | }, 614 | "funding": { 615 | "url": "https://github.com/sponsors/sindresorhus" 616 | } 617 | }, 618 | "node_modules/strip-ansi": { 619 | "version": "7.0.1", 620 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.0.1.tgz", 621 | "integrity": "sha512-cXNxvT8dFNRVfhVME3JAe98mkXDYN2O1l7jmcwMnOslDeESg1rF/OZMtK0nRAhiari1unG5cD4jG3rapUAkLbw==", 622 | "dependencies": { 623 | "ansi-regex": "^6.0.1" 624 | }, 625 | "engines": { 626 | "node": ">=12" 627 | }, 628 | "funding": { 629 | "url": "https://github.com/chalk/strip-ansi?sponsor=1" 630 | } 631 | }, 632 | "node_modules/through": { 633 | "version": "2.3.8", 634 | "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", 635 | "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==" 636 | }, 637 | "node_modules/tmp": { 638 | "version": "0.0.33", 639 | "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", 640 | "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", 641 | "dependencies": { 642 | "os-tmpdir": "~1.0.2" 643 | }, 644 | "engines": { 645 | "node": ">=0.6.0" 646 | } 647 | }, 648 | "node_modules/tslib": { 649 | "version": "2.5.0", 650 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz", 651 | "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==" 652 | }, 653 | "node_modules/type-fest": { 654 | "version": "3.8.0", 655 | "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.8.0.tgz", 656 | "integrity": "sha512-FVNSzGQz9Th+/9R6Lvv7WIAkstylfHN2/JYxkyhhmKFYh9At2DST8t6L6Lref9eYO8PXFTfG9Sg1Agg0K3vq3Q==", 657 | "engines": { 658 | "node": ">=14.16" 659 | }, 660 | "funding": { 661 | "url": "https://github.com/sponsors/sindresorhus" 662 | } 663 | }, 664 | "node_modules/util-deprecate": { 665 | "version": "1.0.2", 666 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", 667 | "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" 668 | }, 669 | "node_modules/wcwidth": { 670 | "version": "1.0.1", 671 | "resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz", 672 | "integrity": "sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==", 673 | "dependencies": { 674 | "defaults": "^1.0.3" 675 | } 676 | }, 677 | "node_modules/wrap-ansi": { 678 | "version": "8.1.0", 679 | "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", 680 | "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", 681 | "dependencies": { 682 | "ansi-styles": "^6.1.0", 683 | "string-width": "^5.0.1", 684 | "strip-ansi": "^7.0.1" 685 | }, 686 | "engines": { 687 | "node": ">=12" 688 | }, 689 | "funding": { 690 | "url": "https://github.com/chalk/wrap-ansi?sponsor=1" 691 | } 692 | } 693 | } 694 | } 695 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "autocoderv1node", 3 | "version": "1.0.0", 4 | "description": "First attempt for building auto coder. Wish me luck.", 5 | "main": "src/index.js", 6 | "type": "module", 7 | "scripts": { 8 | "start": "node src/index.js", 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "author": "https://github.com/Gogolian", 12 | "license": "MIT", 13 | "dependencies": { 14 | "dotenv": "^16.0.3", 15 | "ignore": "^5.2.4", 16 | "inquirer": "^9.1.5", 17 | "klaw-sync": "^6.0.0", 18 | "openai": "^3.2.1" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/agents/agent1.txt: -------------------------------------------------------------------------------- 1 | You are a coding agent that provides json as response prepended only with `JSON:`. 2 | 3 | Your working dir is: 4 | 5 | Your workspace consists of the following codebase structure: 6 | 7 | 8 | 9 | Determine the terminal you should use based on the output of this command: 10 | echo "CMD: %ComSpec% | PS: $PSVersionTable.PSVersion | macOS/Linux: $(uname -a || echo Unknown)" && echo "Python: $(python --version 2>&1 || echo Unknown)" 11 | Terminal output: 12 | 13 | You will receive tasks to analyze and edit the current codebase. To complete each task, you can use the terminal to execute any command that helps you accomplish the goal. 14 | 15 | If you need additional information to complete a task, you may: 16 | 1. Ask the user, providing options on how to proceed. 17 | 2. Request the output of a specific terminal command. 18 | 19 | Your responses should be in json format without any prepended or appended text, code or whitespaces, except `JSON:{`. 20 | Your response structure: 21 | ``` 22 | JSON:{ 23 | "actions": [ 24 | { 25 | "type": "", 26 | "content": "" 27 | }, 28 | ... 29 | ], 30 | "questions": [ 31 | { 32 | "question": "", 33 | "options": ["", "", ...] 34 | }, 35 | ... 36 | ], 37 | "suggestions": ["", "", ...] 38 | } 39 | ``` 40 | 41 | 3 possible action types: 42 | { 43 | type: "command", 44 | content: "" 45 | } 46 | { 47 | type: "update", 48 | filename: "path/filename", 49 | content: "" 50 | } 51 | { 52 | type: "delete", 53 | filename: "path/filename" 54 | } 55 | 56 | no other action types or structures possible. 57 | 58 | While updating the files, make sure that you know what is inside the file so you won't make unnecessary changes. For that, use commands to read the file first. 59 | 60 | the filename always relative to working dir: 61 | Bad "filename" example: C:/code/tryouts/purehtml/src/index.html 62 | Good "filename" example: src/index.html 63 | Good "filename" example: index.html 64 | 65 | Make sure the file exists before attepting to update. 66 | 67 | Example of bad answer: 68 | ` with the following content: 69 | 70 | const module = { 71 | name: 'module', 72 | version: '1.0.0' 73 | }; 74 | 75 | module.exports = module; 76 | 77 | 78 | JSON:{ 79 | "actions": [ 80 | { 81 | "type": "update", 82 | "filename": "src/api/module.js", 83 | "content": "new file content" 84 | } 85 | ] 86 | }` 87 | This answer is bad because it contains additional info BESIDES `JSON:{...}` it should contain just `JSON:{...}` 88 | 89 | Example of bad answer: 90 | ` of the working dir. 91 | 92 | JSON:{ 93 | "actions": [ 94 | { 95 | "type": "update", 96 | "filename": "src/api/module.js", 97 | "content": "new file content\nnew line" 98 | } 99 | ] 100 | }` 101 | This example is bad because it contains " of the working dir.\n\n" besides `JSON:{...}` it should contain just `JSON:{...}` 102 | 103 | Example of good answer: 104 | `JSON:{ 105 | "actions": [ 106 | { 107 | "type": "update", 108 | "filename": "src/api/module.js", 109 | "content": "Hello world!\n\n" 110 | } 111 | ] 112 | }` 113 | This answer is good because it contains NO additional info BESIDES `JSON:{...}` 114 | 115 | THERE SHOULD BE NO TEXT IN YOUR RESPONSE BESIDES JSON OBJECT PREPENDED BY 'JSON:'. DONT PREPEND ANY ADDITIONAL EXPLANATION. 116 | 117 | Your first task is: 118 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 2 | import * as dotenv from 'dotenv' 3 | dotenv.config(); 4 | 5 | import init from './modules/init.js'; 6 | import answer from './modules/answer.js'; 7 | import action from './modules/action.js'; 8 | 9 | (async () => { 10 | 11 | try { 12 | 13 | const agentPrompt = await init(); 14 | 15 | // Get the agent's response 16 | const response = await answer(agentPrompt); 17 | 18 | console.log('agents response:') 19 | console.log(response) 20 | 21 | const result = action(response) 22 | 23 | } catch (error) { 24 | console.error(`An error occurred: ${error.message}`); 25 | } 26 | 27 | })(); -------------------------------------------------------------------------------- /src/modules/action.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | import { exec } from 'child_process'; 3 | import { promisify } from 'util'; 4 | const promisifiedExec = promisify(exec); 5 | 6 | export default async (response) => { 7 | 8 | // TODO: all this code could be abstracted. 9 | const start = response.indexOf('JSON:{') 10 | const end = response.lastIndexOf('}') 11 | const jsonString = response.substring(start + 5, end + 1) 12 | const parsedResponse = JSON.parse(jsonString) 13 | 14 | // Process the agent's response 15 | for (const action of parsedResponse.actions) { 16 | switch (action.type) { 17 | case 'command': 18 | // Execute command 19 | console.log('Executing command:') 20 | console.log(action.content) 21 | const command_res = await promisifiedExec(action.content) 22 | console.log(command_res) 23 | break; 24 | case 'update': 25 | // Update an existing file with provided content 26 | console.log('Updating an existing file with provided content:') 27 | console.log(action?.filename) 28 | console.log(action?.content) 29 | const updateFile_res = await fs.writeFileSync(global.workingDir + '/' + action.filename, action.content, { flag: 'w+', encoding: 'utf-8' }); 30 | console.log(updateFile_res) 31 | break; 32 | case 'delete': 33 | // Delete specified file 34 | console.log('Deleting specified file:') 35 | console.log(action.filename) 36 | const deleteFile_res = await fs.unlinkSync(global.workingDir + '/' + action.filename) 37 | console.log(deleteFile_res) 38 | break; 39 | default: 40 | console.log(`Unknown action type: ${action.type}`); 41 | } 42 | } 43 | 44 | // Ask the user for input based on the agent's questions 45 | for (const question of response.questions) { 46 | console.log(question.question); 47 | console.log(`Options: ${question.options.join(', ')}`); 48 | // Get user input and process it accordingly 49 | } 50 | 51 | // Print suggestions from the agent 52 | for (const suggestion of response.suggestions) { 53 | console.log(`Suggestion: ${suggestion}`); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /src/modules/answer.js: -------------------------------------------------------------------------------- 1 | import { Configuration, OpenAIApi } from "openai"; 2 | import * as dotenv from 'dotenv' 3 | dotenv.config(); 4 | 5 | const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY }); 6 | const openai = new OpenAIApi(configuration); 7 | 8 | export default async (prompt) => { 9 | try { 10 | const completion = await openai.createCompletion({ 11 | model: "text-davinci-003", 12 | prompt, 13 | max_tokens: 2048, 14 | temperature: 0.2, 15 | }); 16 | //console.log(completion) 17 | return completion.data.choices[0].text; 18 | } catch (error) { 19 | console.log(error) 20 | // Consider adjusting the error handling logic for your use case 21 | if (error.response) { 22 | console.error(error.response.status, error.response.data); 23 | } else { 24 | console.error(`Error with OpenAI API request: ${error.message}`); 25 | } 26 | } 27 | return ""; 28 | }; -------------------------------------------------------------------------------- /src/modules/init.js: -------------------------------------------------------------------------------- 1 | import askForWorkingDir from './init/askForWorkingDir.js' 2 | import askForTask from './init/askForTask.js' 3 | import parseDir from './init/parseDir.js' 4 | import parametrizeAgent from './init/parametrizeAgent.js' 5 | import fs from 'fs' 6 | import { exec } from 'child_process'; 7 | import { promisify } from 'util'; 8 | const promisifiedExec = promisify(exec); 9 | 10 | export default async () => { 11 | 12 | console.log('WELCOME TO AUTO-CODER!!!') 13 | console.log('USE IT AT YOUR OWN RISK!!!') 14 | console.log('THIS PROJECT IS FOR EDUCATIONAL PURPOSES ONLY!!!') 15 | 16 | global.workingDir = process.env.WORK_ON_DIRECTORY 17 | 18 | if(process.env.MODE === 'params'){ 19 | global.workingDir = await askForWorkingDir(); 20 | } else { 21 | console.log('workingDir: ', global.workingDir) 22 | } 23 | 24 | const workingDirTree = await parseDir(global.workingDir) 25 | 26 | // TODO: Find some common method to use across multiple sustems, especially i dont know about .stdout if it will work. 27 | const terminalOutput = await promisifiedExec('echo "CMD: %ComSpec% | PS: $PSVersionTable.PSVersion | macOS/Linux: $(uname -a || echo Unknown)" && echo "Python: $(python --version 2>&1 || echo Unknown)"') 28 | 29 | //console.log('terminalOutput', terminalOutput.stdout) 30 | 31 | try { 32 | // Read agent1.txt file 33 | const pureAgentPrompt = await fs.readFileSync(process.env.AGENT, 'utf-8'); 34 | // const pureAgentPrompt = await fs.readFileSync('agents/agent1.txt', 'utf-8'); 35 | 36 | let task = process.env.FIRST_TASK 37 | if(process.env.MODE === 'params'){ 38 | task = await askForTask() 39 | } else { 40 | console.log('task: ', task) 41 | } 42 | 43 | const agentPrompt = parametrizeAgent(pureAgentPrompt, { 44 | workingDir: global.workingDir, 45 | workingDirTree, 46 | terminalOutput: terminalOutput.stdout, 47 | task 48 | }) 49 | 50 | console.log(); 51 | console.log('==========='); 52 | console.log(); 53 | console.log('AGENT CREATED: ', agentPrompt) 54 | console.log(); 55 | console.log('==========='); 56 | console.log(); 57 | 58 | return agentPrompt 59 | 60 | } catch (error) { 61 | console.log(error) 62 | } 63 | return null 64 | } -------------------------------------------------------------------------------- /src/modules/init/askForTask.js: -------------------------------------------------------------------------------- 1 | import inquirer from 'inquirer'; 2 | 3 | export default async () => { 4 | const answers = await inquirer.prompt([ 5 | { 6 | type: 'input', 7 | name: 'task', 8 | message: 'Enter Task:', 9 | }, 10 | ]); 11 | 12 | return answers.task; 13 | }; -------------------------------------------------------------------------------- /src/modules/init/askForWorkingDir.js: -------------------------------------------------------------------------------- 1 | import inquirer from 'inquirer'; 2 | 3 | export default async () => { 4 | const answers = await inquirer.prompt([ 5 | { 6 | type: 'input', 7 | name: 'filePath', 8 | message: 'Enter the directory of your project:', 9 | }, 10 | ]); 11 | 12 | const dirPath = answers.filePath; 13 | return dirPath; 14 | }; -------------------------------------------------------------------------------- /src/modules/init/parametrizeAgent.js: -------------------------------------------------------------------------------- 1 | export default (pureAgentPrompt, parameters) => { 2 | 3 | return pureAgentPrompt 4 | .replace('', parameters.workingDir) 5 | .replace('', parameters.workingDirTree) 6 | .replace('', parameters.terminalOutput) 7 | .replace('', parameters.task) 8 | 9 | } -------------------------------------------------------------------------------- /src/modules/init/parseDir.js: -------------------------------------------------------------------------------- 1 | import ignore from 'ignore'; 2 | import inquirer from 'inquirer'; 3 | import klawSync from 'klaw-sync'; 4 | import fs from 'fs'; 5 | import path from 'path'; 6 | 7 | const getIgnoredPaths = (ignoreFilePath) => { 8 | if (fs.existsSync(ignoreFilePath)) { 9 | const gitignoreContent = fs.readFileSync(ignoreFilePath, 'utf8'); 10 | return ignore().add(gitignoreContent).add('.git').add('.git/*').add('.github').add('.github/*'); 11 | } 12 | return null; 13 | }; 14 | 15 | const displayFilteredDirectoryStructure = (dirPath, ignoredPaths) => { 16 | const items = klawSync(dirPath, { nodir: false, traverseAll: true }); 17 | 18 | const pathItems = [] 19 | 20 | items.forEach((item) => { 21 | try{ 22 | const relativePath = path?.relative(dirPath, `${item?.path}`); 23 | if (!ignoredPaths || !ignoredPaths?.ignores(relativePath)) { 24 | pathItems.push(relativePath); 25 | } 26 | } catch { 27 | console.log('WARNING: couldnt parse path item: ', item); 28 | } 29 | }); 30 | 31 | return pathItems.join('\n') 32 | }; 33 | 34 | export default async (dirPath) => { 35 | const ignoreFilePath = path.join(dirPath, '.gitignore'); 36 | const ignoredPaths = getIgnoredPaths(ignoreFilePath); 37 | 38 | return displayFilteredDirectoryStructure(dirPath, ignoredPaths); 39 | }; --------------------------------------------------------------------------------