This commit is contained in:
Matyi Kari 2025-02-25 14:30:20 -06:00
parent 3157e4e0dd
commit 8fa8e6e623
6 changed files with 123 additions and 17 deletions

8
.prettierrc Normal file
View File

@ -0,0 +1,8 @@
{
"printWidth": 120,
"singleQuote": true,
"useTabs": false,
"tabWidth": 2,
"semi": true,
"bracketSpacing": true
}

21
LICENSE Normal file
View File

@ -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.

75
README.md Normal file
View File

@ -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 <your natural language command>
```
### 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 <command>
```
## License
MIT License - see LICENSE file for details
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.

View File

@ -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",

View File

@ -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();

View File

@ -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/,
},
],
},
};