@lxgicstudios/ai-alias 1.0.0
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.
- package/README.md +21 -0
- package/package.json +14 -0
- package/src/cli.ts +25 -0
- package/src/index.ts +21 -0
- package/tsconfig.json +13 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# ai-alias
|
|
2
|
+
|
|
3
|
+
Generate useful shell aliases from your command history
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g ai-alias
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx ai-alias
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
export OPENAI_API_KEY=sk-...
|
|
21
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lxgicstudios/ai-alias",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Generate useful shell aliases from your command history",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": { "ai-alias": "dist/cli.js" },
|
|
7
|
+
"scripts": { "build": "tsc" },
|
|
8
|
+
"keywords": ["ai", "cli", "developer-tools", "npx", "nodejs", "openai"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"dependencies": { "commander": "^12.1.0", "openai": "^4.73.0", "ora": "^5.4.1" },
|
|
11
|
+
"devDependencies": { "typescript": "^5.6.0", "@types/node": "^22.0.0" },
|
|
12
|
+
"author": "LXGIC Studios",
|
|
13
|
+
"repository": { "type": "git", "url": "https://github.com/LXGIC-Studios/ai-alias" }
|
|
14
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import ora from "ora";
|
|
5
|
+
import { generate } from "./index";
|
|
6
|
+
|
|
7
|
+
const program = new Command();
|
|
8
|
+
|
|
9
|
+
program
|
|
10
|
+
.name("ai-alias")
|
|
11
|
+
.description("Generate useful shell aliases from your command history")
|
|
12
|
+
.version("1.0.0")
|
|
13
|
+
.action(async () => {
|
|
14
|
+
const spinner = ora("Generating...").start();
|
|
15
|
+
try {
|
|
16
|
+
const result = await generate(process.cwd());
|
|
17
|
+
spinner.succeed("Done:\n");
|
|
18
|
+
console.log(result);
|
|
19
|
+
} catch (err: any) {
|
|
20
|
+
spinner.fail(`Error: ${err.message}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
program.parse();
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
|
|
5
|
+
const openai = new OpenAI();
|
|
6
|
+
|
|
7
|
+
export async function generate(input: string): Promise<string> {
|
|
8
|
+
const histFile = process.env.HISTFILE || path.join(process.env.HOME || "~", ".zsh_history");
|
|
9
|
+
let history = "";
|
|
10
|
+
try { history = fs.readFileSync(histFile, "utf-8").split("\n").slice(-500).join("\n"); } catch { history = "No history file found. Generate common useful aliases for developers."; }
|
|
11
|
+
const userContent = `Analyze this shell history and suggest aliases:\n\n${history}`;
|
|
12
|
+
const response = await openai.chat.completions.create({
|
|
13
|
+
model: "gpt-4o-mini",
|
|
14
|
+
messages: [
|
|
15
|
+
{ role: "system", content: `You are a shell productivity expert. Analyze the command history and suggest useful shell aliases. Output them in a format ready to paste into .bashrc or .zshrc. Group by category (git, docker, npm, etc). Only suggest aliases for commands used frequently or that are long to type.` },
|
|
16
|
+
{ role: "user", content: userContent }
|
|
17
|
+
],
|
|
18
|
+
temperature: 0.7,
|
|
19
|
+
});
|
|
20
|
+
return response.choices[0].message.content || "";
|
|
21
|
+
}
|
package/tsconfig.json
ADDED