agent-cli-kit 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 +80 -0
- package/bin/cli.js +43 -0
- package/lib/index.js +78 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# agent-cli-kit
|
|
2
|
+
|
|
3
|
+
A starter kit for AI agents building CLI tools. Handles config, logging, API calls, and auth.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install agent-cli-kit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const { AgentCLI } = require('agent-cli-kit');
|
|
15
|
+
const { program } = require('commander');
|
|
16
|
+
|
|
17
|
+
// Create your agent
|
|
18
|
+
const agent = new AgentCLI('my-agent', '1.0.0');
|
|
19
|
+
|
|
20
|
+
// Add commands
|
|
21
|
+
program
|
|
22
|
+
.command('action <target>')
|
|
23
|
+
.action((target) => {
|
|
24
|
+
agent.log.success(`Action on ${target}`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
program.parse(process.argv);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
✅ Config management (auto-saved to ~/.agent-config/)
|
|
33
|
+
✅ Logging helpers (success, error, warn, info)
|
|
34
|
+
✅ API call wrapper with timeout
|
|
35
|
+
✅ Commander.js pre-integrated
|
|
36
|
+
✅ Zero additional setup needed
|
|
37
|
+
|
|
38
|
+
## Built-in Methods
|
|
39
|
+
|
|
40
|
+
### Logging
|
|
41
|
+
- `agent.log.success(msg)` — ✅ messages
|
|
42
|
+
- `agent.log.error(msg)` — ❌ errors
|
|
43
|
+
- `agent.log.warn(msg)` — ⚠️ warnings
|
|
44
|
+
- `agent.log.info(msg)` — ℹ️ info
|
|
45
|
+
- `agent.log.section(title)` — 📍 section header
|
|
46
|
+
- `agent.log.json(obj)` — Pretty-print JSON
|
|
47
|
+
|
|
48
|
+
### Config
|
|
49
|
+
- `agent.get(key)` — Get config value
|
|
50
|
+
- `agent.set(key, value)` — Save config value
|
|
51
|
+
|
|
52
|
+
### API
|
|
53
|
+
- `await agent.api(url, options)` — Fetch with timeout + error handling
|
|
54
|
+
|
|
55
|
+
## Example: Weather Agent
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
const { AgentCLI } = require('agent-cli-kit');
|
|
59
|
+
const { program } = require('commander');
|
|
60
|
+
|
|
61
|
+
const agent = new AgentCLI('weather-agent', '1.0.0');
|
|
62
|
+
|
|
63
|
+
program
|
|
64
|
+
.command('weather <city>')
|
|
65
|
+
.action(async (city) => {
|
|
66
|
+
try {
|
|
67
|
+
const data = await agent.api(`https://api.example.com/weather?city=${city}`);
|
|
68
|
+
agent.log.section(`Weather in ${city}`);
|
|
69
|
+
agent.log.info(`Temperature: ${data.temp}°C`);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
agent.log.error(`Could not fetch weather`);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
program.parse(process.argv);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { AgentCLI } = require('../lib/index.js');
|
|
4
|
+
const { program } = require('commander');
|
|
5
|
+
|
|
6
|
+
// Initialize your agent CLI
|
|
7
|
+
const agent = new AgentCLI('my-agent', '1.0.0');
|
|
8
|
+
|
|
9
|
+
program
|
|
10
|
+
.name(agent.name)
|
|
11
|
+
.version(agent.version)
|
|
12
|
+
.description('Your AI agent CLI');
|
|
13
|
+
|
|
14
|
+
// Example: config command
|
|
15
|
+
program
|
|
16
|
+
.command('config')
|
|
17
|
+
.description('Manage configuration')
|
|
18
|
+
.action(() => {
|
|
19
|
+
agent.log.section('Configuration');
|
|
20
|
+
agent.log.json(agent.config);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Example: set API key
|
|
24
|
+
program
|
|
25
|
+
.command('auth <key>')
|
|
26
|
+
.description('Set API key')
|
|
27
|
+
.action((key) => {
|
|
28
|
+
agent.set('api_key', key);
|
|
29
|
+
agent.log.success('API key saved');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Example: status command
|
|
33
|
+
program
|
|
34
|
+
.command('status')
|
|
35
|
+
.description('Check agent status')
|
|
36
|
+
.action(() => {
|
|
37
|
+
agent.log.section('Agent Status');
|
|
38
|
+
agent.log.info(`Name: ${agent.name}`);
|
|
39
|
+
agent.log.info(`Version: ${agent.version}`);
|
|
40
|
+
agent.log.info(`Configured: ${Object.keys(agent.config).length > 0 ? 'Yes' : 'No'}`);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
program.parse(process.argv);
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Agent CLI Framework - Core Library
|
|
2
|
+
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const fs = require('fs-extra');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
class AgentCLI {
|
|
8
|
+
constructor(name, version) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.version = version;
|
|
11
|
+
this.config = {};
|
|
12
|
+
this.loadConfig();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Load config from ~/.agent-config/[name].json
|
|
16
|
+
loadConfig() {
|
|
17
|
+
const configDir = path.join(process.env.HOME || '/tmp', '.agent-config');
|
|
18
|
+
const configFile = path.join(configDir, `${this.name}.json`);
|
|
19
|
+
|
|
20
|
+
if (fs.existsSync(configFile)) {
|
|
21
|
+
this.config = fs.readJsonSync(configFile);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Save config
|
|
26
|
+
saveConfig() {
|
|
27
|
+
const configDir = path.join(process.env.HOME || '/tmp', '.agent-config');
|
|
28
|
+
const configFile = path.join(configDir, `${this.name}.json`);
|
|
29
|
+
|
|
30
|
+
fs.ensureDirSync(configDir);
|
|
31
|
+
fs.writeJsonSync(configFile, this.config, { spaces: 2 });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Logger helper
|
|
35
|
+
log = {
|
|
36
|
+
success: (msg) => console.log(chalk.green(`✅ ${msg}`)),
|
|
37
|
+
error: (msg) => console.error(chalk.red(`❌ ${msg}`)),
|
|
38
|
+
warn: (msg) => console.warn(chalk.yellow(`⚠️ ${msg}`)),
|
|
39
|
+
info: (msg) => console.log(chalk.blue(`ℹ️ ${msg}`)),
|
|
40
|
+
section: (msg) => console.log(chalk.cyan(`\n📍 ${msg}\n`)),
|
|
41
|
+
json: (obj) => console.log(JSON.stringify(obj, null, 2))
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// API call helper
|
|
45
|
+
async api(url, options = {}) {
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(url, {
|
|
48
|
+
timeout: options.timeout || 10000,
|
|
49
|
+
headers: {
|
|
50
|
+
'Content-Type': 'application/json',
|
|
51
|
+
...options.headers
|
|
52
|
+
},
|
|
53
|
+
...options
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
throw new Error(`API Error: ${response.status}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return await response.json();
|
|
61
|
+
} catch (err) {
|
|
62
|
+
this.log.error(`API call failed: ${err.message}`);
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Config getter/setter
|
|
68
|
+
get(key) {
|
|
69
|
+
return this.config[key];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
set(key, value) {
|
|
73
|
+
this.config[key] = value;
|
|
74
|
+
this.saveConfig();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = { AgentCLI };
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agent-cli-kit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Starter kit for AI agents building CLIs. Includes auth, config, logging, API helpers.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"agent-cli-kit": "bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo 'tests coming soon'"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"agent",
|
|
14
|
+
"cli",
|
|
15
|
+
"framework",
|
|
16
|
+
"starter",
|
|
17
|
+
"template",
|
|
18
|
+
"ai"
|
|
19
|
+
],
|
|
20
|
+
"author": "Bagalobsta <bagalobsta@protonmail.com>",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/bagalobsta/agent-cli-kit.git"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"chalk": "^4.1.2",
|
|
28
|
+
"commander": "^11.1.0",
|
|
29
|
+
"dotenv": "^16.3.1",
|
|
30
|
+
"fs-extra": "^11.2.0"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=14.0.0"
|
|
34
|
+
}
|
|
35
|
+
}
|