@seberto/agcp 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/bin/agcp.js ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from "commander";
4
+ import chalk from "chalk";
5
+ import { confirm } from "@inquirer/prompts";
6
+ import { execSync } from "child_process";
7
+ import generateCommand from "../service/ollama.js";
8
+
9
+ const program = new Command();
10
+
11
+ program
12
+ .name("agcp")
13
+ .description("AI CLI that generates and runs shell commands")
14
+ .version("1.0.0")
15
+ .argument("<prompt>", "Describe what you want to do")
16
+ .action(async (prompt) => {
17
+ try {
18
+ console.log(chalk.yellow("\n⏳ Generating command..."));
19
+
20
+ const command = await generateCommand(prompt);
21
+
22
+ console.log(chalk.cyan(`\n💡 Suggested command:\n ${chalk.bold(command)}\n`));
23
+
24
+ const shouldRun = await confirm({
25
+ message: "Execute this command?",
26
+ default: false,
27
+ });
28
+
29
+ if (shouldRun) {
30
+ console.log(chalk.green("\n▶ Running...\n"));
31
+ execSync(command, { stdio: "inherit" });
32
+ } else {
33
+ console.log(chalk.gray("\nAborted."));
34
+ }
35
+ } catch (err) {
36
+ if (err.code === "ECONNREFUSED") {
37
+ console.error(chalk.red("\n✖ Could not connect to Ollama. Make sure it is running on http://localhost:11434"));
38
+ } else {
39
+ console.error(chalk.red(`\n✖ Error: ${err.message}`));
40
+ }
41
+ process.exit(1);
42
+ }
43
+ });
44
+
45
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@seberto/agcp",
3
+ "version": "1.0.0",
4
+ "description": "AI CLI that generates and runs shell commands",
5
+ "type": "module",
6
+ "bin": {
7
+ "agcp": "bin/agcp.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "service"
12
+ ],
13
+ "scripts": {
14
+ "start": "node ./bin/agcp.js"
15
+ },
16
+ "engines": {
17
+ "node": ">=18.0.0"
18
+ },
19
+ "keywords": [
20
+ "cli",
21
+ "ollama",
22
+ "ai",
23
+ "shell",
24
+ "command"
25
+ ],
26
+ "author": "seberto",
27
+ "license": "ISC",
28
+ "dependencies": {
29
+ "@inquirer/prompts": "^7.5.2",
30
+ "axios": "^1.9.0",
31
+ "chalk": "^5.4.1",
32
+ "commander": "^14.0.0"
33
+ }
34
+ }
@@ -0,0 +1,20 @@
1
+ import axios from "axios";
2
+
3
+ async function generateCommand(userPrompt) {
4
+ const { data } = await axios.get("http://localhost:11434/api/tags");
5
+ const model = data.models?.[0]?.name;
6
+
7
+ if (!model) throw new Error("No Ollama models found. Run 'ollama pull <model>' first.");
8
+
9
+ const prompt = `Convert the following text into a shell command. Return only the command, no explanation, no markdown.\n\n${userPrompt}`;
10
+
11
+ const response = await axios.post("http://localhost:11434/api/generate", {
12
+ model,
13
+ prompt,
14
+ stream: false,
15
+ });
16
+
17
+ return response.data.response.trim();
18
+ }
19
+
20
+ export default generateCommand;