diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..8d3dfb0 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "printWidth": 120, + "singleQuote": true, + "useTabs": false, + "tabWidth": 2, + "semi": true, + "bracketSpacing": true +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..49eefe6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Matyi Kari + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0c12724 --- /dev/null +++ b/README.md @@ -0,0 +1,75 @@ +# zzk + +A command-line interface tool that converts natural language instructions into shell commands using OpenAI's GPT-4. + +## Installation + +```bash +pnpm add -g zzk +``` + +## Prerequisites + +Before using this tool, you need to: + +1. Have an OpenAI API key +2. Create a `.env` file in your project root with: + +```bash +OPENAI_API_KEY=your_api_key_here +``` + +## Usage + +```bash +zzk +``` + +### Examples + +```bash +# List all files in the current directory +zzk show me all files in this folder + +# Find large files +zzk find files larger than 100MB + +# Search for text in files +zzk search for "hello world" in all javascript files +``` + +The tool will: + +1. Process your natural language input +2. Generate an appropriate shell command +3. Show you the command for confirmation +4. Execute the command upon your approval + +## Development + +To set up the development environment: + +```bash +# Clone the repository +git clone [your-repo-url] + +# Install dependencies +pnpm install + +# Build the project +pnpm build + +# Create a global link +pnpm link --global + +# Now you can use the development version globally +zzk +``` + +## License + +MIT License - see LICENSE file for details + +## Contributing + +Contributions are welcome! Please feel free to submit a Pull Request. diff --git a/package.json b/package.json index 4c249f2..7529dc2 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,17 @@ { "name": "zzk", - "version": "0.0.1", + "version": "0.1.0", "description": "", "main": "index.js", "scripts": { - "build": "rimraf dist && webpack", - "start": "node -r dotenv/config dist/index.js", - "test": "echo \"Error: no test specified\" && exit 1" + "build": "rimraf dist && webpack" + }, + "bin": { + "zzk": "dist/index.js" }, "keywords": [], - "author": "", - "license": "ISC", + "author": "Matyi Kari", + "license": "MIT", "devDependencies": { "@types/node": "^22.13.5", "rimraf": "^6.0.1", diff --git a/src/index.ts b/src/index.ts index a47d312..ccbc957 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ +#!/usr/bin/env node + import { config } from 'dotenv'; import { exec } from 'child_process'; import OpenAI from 'openai'; @@ -25,7 +27,7 @@ if (!userInput) { function confirmExecution(command: string) { const rl = readline.createInterface({ input: process.stdin, - output: process.stdout + output: process.stdout, }); rl.question(`\nRun this command? [y/N]: ${command} `, (answer) => { @@ -60,11 +62,10 @@ async function processCommand(input: string) { messages: [ { role: 'system', - content: - "Convert the user's request into a shell command without explanation." + content: "Convert the user's request into a shell command without explanation.", }, - { role: 'user', content: input } - ] + { role: 'user', content: input }, + ], }); const command = response.choices[0]?.message?.content?.trim(); diff --git a/webpack.config.js b/webpack.config.js index 0ed3a2a..f89d386 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,18 +6,18 @@ module.exports = { mode: 'production', output: { filename: 'index.js', - path: path.resolve(__dirname, 'dist') + path: path.resolve(__dirname, 'dist'), }, resolve: { - extensions: ['.ts', '.js'] + extensions: ['.ts', '.js'], }, module: { rules: [ { test: /\.ts$/, use: 'ts-loader', - exclude: /node_modules/ - } - ] - } + exclude: /node_modules/, + }, + ], + }, };