{"id":18763046,"url":"https://github.com/ntegrals/magic-cli","last_synced_at":"2025-04-13T04:32:23.765Z","repository":{"id":158109633,"uuid":"628373633","full_name":"ntegrals/magic-cli","owner":"ntegrals","description":"GPT-4 powered CLI. Self-repairing code for any language, programming language translation, automatic unit tests, and much more","archived":false,"fork":false,"pushed_at":"2023-11-20T20:39:51.000Z","size":2072,"stargazers_count":88,"open_issues_count":1,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-26T21:38:29.079Z","etag":null,"topics":["artificial-intelligence","gpt-4","openai"],"latest_commit_sha":null,"homepage":"https://julianschoen.co","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ntegrals.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-15T18:41:13.000Z","updated_at":"2025-02-28T20:46:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"ff29f142-275c-4b56-80b5-cb0caa89e1c3","html_url":"https://github.com/ntegrals/magic-cli","commit_stats":null,"previous_names":["ntegrals/magic-cli"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntegrals%2Fmagic-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntegrals%2Fmagic-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntegrals%2Fmagic-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntegrals%2Fmagic-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ntegrals","download_url":"https://codeload.github.com/ntegrals/magic-cli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248664014,"owners_count":21141876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","gpt-4","openai"],"created_at":"2024-11-07T18:24:29.291Z","updated_at":"2025-04-13T04:32:23.431Z","avatar_url":"https://github.com/ntegrals.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/ntegrals"],"categories":[],"sub_categories":[],"readme":"\u003ca name=\"readme-top\"\u003e\u003c/a\u003e\n\n\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/ntegrals/magic-cli\"\u003e\n    \u003cimg src=\"images/logo.png\" alt=\"Logo\" width=\"80\" height=\"80\"\u003e\n  \u003c/a\u003e\n\n\u003ch3 align=\"center\"\u003eMagic CLI\u003c/h3\u003e\n\n  \u003cp align=\"center\"\u003e\n    Self-repairing code for any language, programming language translation, automatic unit tests, and much more\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/ntegrals/magic-cli\"\u003eView Demo\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/ntegrals/magic-cli/issues\"\u003eReport Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/ntegrals/magic-cli/issues\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\u003c!-- \u003ca href=\"https://youtu.be/GyRd0qW0mYo\"\u003e\n    \u003cimg src=\"images/demo.png\" alt=\"Logo\"\u003e\n  \u003c/a\u003e --\u003e\n\n## Features\n\n    ✅ Self-Repairing Code              [Runs a script in any language and fixes it upon crash]\n    ✅ Generate Unit Tests              [Generates unit tests for a code file]\n    ✅ Conduct Code Reviews             [Reviews a code file]\n    ✅ Translate Programming Languages  [Converts a code file to another language]\n    ✅ ELI5 Code                        [Generates an ELI5 explanation]\n    ✅ Refactor Code                    [Refactors the code]\n    ✅ Document Code                    [Adds documentation to the code]\n    ✅ Best Practices                   [Converts the code to use the best practices]\n    ✅ Arbitrary Input                  [Prompt GPT-4 anything]\n    🟨 Reflexion                        [GPT reflects on it's answers to improve the output quality]\n    🟨 Add new feature                  [Adds a new feature based on an input file]\n    🟨 Increase context window          [Increase context window with vector embeddings]\n    🟨 Process directories              [CLI can process directories and not only files]\n\n## Installation\n\nYou need to have [Node.js](https://nodejs.org/en) installed.\n\n1. Get an OpenAI API Key at [https://openai.com/](https://openai.com/)\n\n   ❗️ By default the model uses GPT-4. If you don't have access to GPT-4 yet, you have to use the -g3 flag. (It will then use the GPT-3.5 Turbo model)\n\n2. Install the CLI via npm\n   ```sh\n   npm install -g the-magic-cli\n   ```\n3. The CLI can then simply be called by running:\n   ```\n   magic\n   ```\n   or\n   ```\n   magic-cli\n   ```\n   I'm going to use the latter in the following examples for the sake of brevity.\n4. Add your OpenAI API key (It's only stored on your device)\n   ```sh\n   magic -ak \"sk-9jfoa...\"\n   ```\n\n\u003c!-- USAGE EXAMPLES --\u003e\n\n## Examples\n\n### 1. Self-Repair\n\nThis command will run a code file in any language and automatically try to fix it when it crashes or has a bug.\n\n#### 1.1 Self-Repair a Python file\n\nRun the magic command in a directory with a file called `test.py`:\n\n```sh\n  magic -f test.py python3\n```\n\nThis command will run the file `test.py` with the interpreter `python3`.\n\n#### 1.2 Self-Repair a TypeScript file\n\nRun the magic command in a directory with a file called `test.ts`:\n\n```sh\n  magic -f test.py ts-node\n```\n\nThis command will run the file `test.ts` with the interpreter `ts-node`.\n\n### 2. Translate from Python to TypeScript\n\nRun the magic command in a directory with a file called `test.py`. We also need to specify a file that we want to write to `test.ts` in this case (If not the CLI will only log to the console). Now Magic CLI will automatically translate the code to TypeScript.\n\n```sh\n  magic -l test.py TypeScript -o test.ts\n```\n\n### 3. Conduct a code review\n\nRun the magic command in a directory with a file called `test.py`. In this case we might only want to view the output in the terminal, so we don't need to specify an output file. This command will review the code and give you feedback on how to improve it.\n\n```sh\n  magic -r test.py\n```\n\n### 4. Generate unit tests\n\nRun the magic command in a directory with a file called `hello.ts` with the testing framework that we want to use (Jest in this case). We also need to specify the file that we want to write to `hello.test.ts`. Now Magic CLI will automatically generate unit tests for the code.\n\n```sh\n  magic -t hello.ts Jest -o hello.test.ts\n```\n\n### 4. Use custom prompt\n\nUsing a custom prompt is also really convenient.\n\nYou have two options:\n\n1. Use the -x flag. This flag accepts a file input and a custom prompt.\n\n```sh\n  magic -x hello.ts \"Check this code for security vulnerabilities\"\n```\n\n2. Use the -z flag. This flag only accepts a custom prompt. (Without a file input)\n\n```sh\n  magic -z \"Why is the answer to everything 42?\"\n```\n\nThese methods can also be used to generate entirely new features.\n\n```sh\n  magic -x hello.ts \"Given the provided code, create new a functional React component, that implements a loading spinner. Only return the code.\" -o spinner.ts\n```\n\nThe command above reads the \"hello.ts\" file, sends the code with your prompt to GPT-4 and writes the result to \"spinner.ts\".\n\n## Usage\n\nRun `magic -h` to see all available commands\n\n    Options:\n    -v, --version                             output the current version\n    -r, --review  \u003cfilePath\u003e                  code review for a file\n    -i, --improve  \u003cfilePath\u003e                 refactor the code\n    -b, --best  \u003cfilePath\u003e                    convert the code to the best practices\n    -f, --fix [filePath interpreter...]       fix the code recursively\n    -l, --lang [filePath targetLanguage...]   convert the code to a different language\n    -e, --eli5 \u003cfilePath\u003e                     explain the code in simple terms\n    -t, --test [filePath framework...]        generate unit tests for the code\n    -d, --document \u003cfilePath\u003e                 generate documentation for the code\n    -x, --arbitraryFile [filePath prompt...]  accepts any instruction (prompt needs to be in quotes)\n    -z, --arbitrary \u003cprompt\u003e                  accepts any instruction\n    -o, --output [filePath]                   the output file path\n    -s, --silent                              prevents logging the stream to the console\n    -g3, --gpt3                               only uses GPT-3.5\n    -ak, --addkey [apiKey]                    add your OpenAI API key to the the environment\n    -dk, --deletekey                          delete your OpenAI API key from the environment\n    -pk, --printkey                           print your OpenAI API key\n    -h, --help                                display help for command\n\n## Contact\n\nHi! Thanks for checking out and using this library. If you are interested in discussing your project, require mentorship, consider hiring me, or just wanna chat - I'm happy to talk.\n\nYou can send me an email to get in touch: j.schoen@mail.com or message me on Twitter: [@julianschoen](https://twitter.com/julianschoen)\n\nIf you'd just want to give something back, I've got a Buy Me A Coffee account:\n\n\u003ca href=\"https://www.buymeacoffee.com/ntegrals\"\u003e\n\u003cimg src=\"images/buymeacoffee.png\" alt=\"buymeacoffee\" width=\"192\"\u003e\n\u003c/a\u003e\n\nThanks and have an awesome day 👋\n\n## Disclaimer\n\nMagic CLI, is an experimental application and is provided \"as-is\" without any warranty, express or implied. By using this software, you agree to assume all risks associated with its use, including but not limited to data loss, system failure, or any other issues that may arise.\n\nThe developers and contributors of this project do not accept any responsibility or liability for any losses, damages, or other consequences that may occur as a result of using this software. You are solely responsible for any decisions and actions taken based on the information provided by Magic CLI.\n\nPlease note that the use of the GPT-4 language model can be expensive due to its token usage. By utilizing this project, you acknowledge that you are responsible for monitoring and managing your own token usage and the associated costs. It is highly recommended to check your OpenAI API usage regularly and set up any necessary limits or alerts to prevent unexpected charges.\n\nBy using Magic CLI, you agree to indemnify, defend, and hold harmless the developers, contributors, and any affiliated parties from and against any and all claims, damages, losses, liabilities, costs, and expenses (including reasonable attorneys' fees) arising from your use of this software or your violation of these terms.\n\n\u003c!-- LICENSE --\u003e\n\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n[product-screenshot]: images/demo.png\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntegrals%2Fmagic-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fntegrals%2Fmagic-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntegrals%2Fmagic-cli/lists"}