@nicolasmondain/cli-agent 3.0.2
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 +183 -0
- package/dist/cli/commands/list.command.d.ts +48 -0
- package/dist/cli/commands/list.command.d.ts.map +1 -0
- package/dist/cli/commands/list.command.js +87 -0
- package/dist/cli/commands/list.command.js.map +1 -0
- package/dist/cli/commands/mcp-serve.command.d.ts +13 -0
- package/dist/cli/commands/mcp-serve.command.d.ts.map +1 -0
- package/dist/cli/commands/mcp-serve.command.js +42 -0
- package/dist/cli/commands/mcp-serve.command.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +111 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/command/dynamic-command.factory.d.ts +16 -0
- package/dist/command/dynamic-command.factory.d.ts.map +1 -0
- package/dist/command/dynamic-command.factory.js +161 -0
- package/dist/command/dynamic-command.factory.js.map +1 -0
- package/dist/config/config-loader.d.ts +24 -0
- package/dist/config/config-loader.d.ts.map +1 -0
- package/dist/config/config-loader.js +95 -0
- package/dist/config/config-loader.js.map +1 -0
- package/dist/config/config-schema.d.ts +73 -0
- package/dist/config/config-schema.d.ts.map +1 -0
- package/dist/config/config-schema.js +7 -0
- package/dist/config/config-schema.js.map +1 -0
- package/dist/config/config-validator.d.ts +20 -0
- package/dist/config/config-validator.d.ts.map +1 -0
- package/dist/config/config-validator.js +162 -0
- package/dist/config/config-validator.js.map +1 -0
- package/dist/executor/js-executor.d.ts +29 -0
- package/dist/executor/js-executor.d.ts.map +1 -0
- package/dist/executor/js-executor.js +77 -0
- package/dist/executor/js-executor.js.map +1 -0
- package/dist/executor/script-executor.d.ts +33 -0
- package/dist/executor/script-executor.d.ts.map +1 -0
- package/dist/executor/script-executor.js +45 -0
- package/dist/executor/script-executor.js.map +1 -0
- package/dist/executor/shell-executor.d.ts +33 -0
- package/dist/executor/shell-executor.d.ts.map +1 -0
- package/dist/executor/shell-executor.js +126 -0
- package/dist/executor/shell-executor.js.map +1 -0
- package/dist/executor/ts-executor.d.ts +33 -0
- package/dist/executor/ts-executor.d.ts.map +1 -0
- package/dist/executor/ts-executor.js +134 -0
- package/dist/executor/ts-executor.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/infra/logger.d.ts +42 -0
- package/dist/infra/logger.d.ts.map +1 -0
- package/dist/infra/logger.js +96 -0
- package/dist/infra/logger.js.map +1 -0
- package/dist/infra/output.d.ts +11 -0
- package/dist/infra/output.d.ts.map +1 -0
- package/dist/infra/output.js +70 -0
- package/dist/infra/output.js.map +1 -0
- package/dist/mcp/mcp-server.d.ts +21 -0
- package/dist/mcp/mcp-server.d.ts.map +1 -0
- package/dist/mcp/mcp-server.js +183 -0
- package/dist/mcp/mcp-server.js.map +1 -0
- package/dist/services/file-system.service.d.ts +53 -0
- package/dist/services/file-system.service.d.ts.map +1 -0
- package/dist/services/file-system.service.js +100 -0
- package/dist/services/file-system.service.js.map +1 -0
- package/dist/services/naming.service.d.ts +40 -0
- package/dist/services/naming.service.d.ts.map +1 -0
- package/dist/services/naming.service.js +86 -0
- package/dist/services/naming.service.js.map +1 -0
- package/dist/services/naming.service.test.d.ts +2 -0
- package/dist/services/naming.service.test.d.ts.map +1 -0
- package/dist/services/naming.service.test.js +99 -0
- package/dist/services/naming.service.test.js.map +1 -0
- package/dist/types/index.d.ts +51 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +14 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# cli-agent
|
|
2
|
+
|
|
3
|
+
> Turn your scripts into AI-powered tools
|
|
4
|
+
|
|
5
|
+
cli-agent is an MCP server that lets AI assistants like Claude execute your scripts through natural language.
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
1. You define your scripts in `.cli-agent.json`
|
|
10
|
+
2. cli-agent exposes them as MCP tools
|
|
11
|
+
3. Claude understands what they do and runs them when needed
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
User: "Deploy to staging"
|
|
15
|
+
↓
|
|
16
|
+
Claude matches intent → deploy --env staging
|
|
17
|
+
↓
|
|
18
|
+
Your script runs → Result returned to Claude
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### 1. Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install -g @nicolasmondain/cli-agent
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 2. Create `.cli-agent.json`
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"name": "cli-agent",
|
|
34
|
+
"commands": [
|
|
35
|
+
{
|
|
36
|
+
"name": "deploy",
|
|
37
|
+
"description": "Deploy the app to staging or production",
|
|
38
|
+
"script": "./scripts/deploy.sh",
|
|
39
|
+
"options": [
|
|
40
|
+
{ "flags": "-e, --env <env>", "choices": ["staging", "production"] }
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 3. Configure Claude Code
|
|
48
|
+
|
|
49
|
+
Add to your Claude Code MCP settings: `.claude/mcp.json`
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"mcpServers": {
|
|
54
|
+
"cli-agent": {
|
|
55
|
+
"command": "npx",
|
|
56
|
+
"args": ["cli-agent", "mcp:serve"]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For Zed, add to your settings:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"context_servers": {
|
|
67
|
+
"mcp-server-cli-agent": {
|
|
68
|
+
"command": "npx",
|
|
69
|
+
"args": ["@nicolasmondain/cli-agent", "mcp:serve"]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Done. Claude can now run your scripts.
|
|
76
|
+
|
|
77
|
+
## Writing Scripts
|
|
78
|
+
|
|
79
|
+
Scripts can be JavaScript, TypeScript, or shell scripts.
|
|
80
|
+
|
|
81
|
+
### JavaScript (.js)
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
export default async function(context) {
|
|
85
|
+
const env = context.options.env;
|
|
86
|
+
// your logic here
|
|
87
|
+
return { success: true, message: `Deployed to ${env}` };
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### TypeScript (.ts)
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import type { ScriptContext, CommandResult } from '@nicolasmondain/cli-agent';
|
|
95
|
+
|
|
96
|
+
export default async function(context: ScriptContext): Promise<CommandResult> {
|
|
97
|
+
const env = context.options.env as string;
|
|
98
|
+
return { success: true, message: `Deployed to ${env}` };
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Shell (.sh)
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
#!/bin/bash
|
|
106
|
+
ENV="${CLI_AGENT_OPT_ENV}"
|
|
107
|
+
echo "Deploying to $ENV..."
|
|
108
|
+
echo '{"success": true}'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Configuration
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"name": "cli-agent",
|
|
116
|
+
"commands": [
|
|
117
|
+
{
|
|
118
|
+
"name": "command-name",
|
|
119
|
+
"description": "What this command does (helps Claude understand when to use it)",
|
|
120
|
+
"script": "./path/to/script.js",
|
|
121
|
+
"arguments": [
|
|
122
|
+
{ "name": "arg", "description": "Positional argument", "required": true }
|
|
123
|
+
],
|
|
124
|
+
"options": [
|
|
125
|
+
{ "flags": "-o, --option <value>", "description": "Named option", "default": "value" }
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Configuration locations
|
|
133
|
+
|
|
134
|
+
cli-agent looks for configuration in this order:
|
|
135
|
+
|
|
136
|
+
1. `--config <path>` flag
|
|
137
|
+
2. `.cli-agent.json` in current directory
|
|
138
|
+
3. `cli-agent` field in `package.json`
|
|
139
|
+
4. `~/.cli-agent.json` (global)
|
|
140
|
+
|
|
141
|
+
## CLI Usage
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# Start MCP server (used by Claude Code)
|
|
145
|
+
cli-agent mcp:serve
|
|
146
|
+
|
|
147
|
+
# List available commands
|
|
148
|
+
cli-agent list
|
|
149
|
+
|
|
150
|
+
# Run a command directly
|
|
151
|
+
cli-agent deploy --env staging
|
|
152
|
+
|
|
153
|
+
# JSON output for scripting
|
|
154
|
+
cli-agent deploy --env staging --format json
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Script Context
|
|
158
|
+
|
|
159
|
+
Scripts receive a context object with:
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
interface ScriptContext {
|
|
163
|
+
args: Record<string, unknown>; // Positional arguments
|
|
164
|
+
options: Record<string, unknown>; // Named options
|
|
165
|
+
cwd: string; // Current working directory
|
|
166
|
+
format: 'human' | 'json'; // Output format
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Scripts must return:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
interface CommandResult {
|
|
174
|
+
success: boolean;
|
|
175
|
+
message?: string; // Human-readable message
|
|
176
|
+
data?: unknown; // Structured data
|
|
177
|
+
error?: string; // Error message if success is false
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
MIT
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List Command
|
|
3
|
+
*
|
|
4
|
+
* Built-in command that lists all available commands from configuration.
|
|
5
|
+
* Enables AI agents to discover commands dynamically.
|
|
6
|
+
*/
|
|
7
|
+
import { Command } from 'commander';
|
|
8
|
+
import type { CliConfig } from '../../config/config-schema.js';
|
|
9
|
+
import type { CommandResult } from '../../types/index.js';
|
|
10
|
+
/**
|
|
11
|
+
* Data structure for list command output
|
|
12
|
+
*/
|
|
13
|
+
export interface ListCommandData {
|
|
14
|
+
name: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
version?: string;
|
|
17
|
+
commands: Array<{
|
|
18
|
+
name: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
script: string;
|
|
21
|
+
arguments?: Array<{
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
required?: boolean;
|
|
25
|
+
variadic?: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
options?: Array<{
|
|
28
|
+
flags: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
default?: unknown;
|
|
31
|
+
required?: boolean;
|
|
32
|
+
choices?: string[];
|
|
33
|
+
}>;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create the list command result
|
|
38
|
+
*/
|
|
39
|
+
export declare function createListResult(config: CliConfig | null): CommandResult<ListCommandData | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Format list output for human display
|
|
42
|
+
*/
|
|
43
|
+
export declare function formatListHuman(config: CliConfig): string;
|
|
44
|
+
/**
|
|
45
|
+
* Create the list command
|
|
46
|
+
*/
|
|
47
|
+
export declare function createListCommand(config: CliConfig | null): Command;
|
|
48
|
+
//# sourceMappingURL=list.command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/list.command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAA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
|
4
|
+
* Built-in command that lists all available commands from configuration.
|
|
5
|
+
* Enables AI agents to discover commands dynamically.
|
|
6
|
+
*/
|
|
7
|
+
import { Command } from 'commander';
|
|
8
|
+
import { outputResult } from '../../infra/output.js';
|
|
9
|
+
/**
|
|
10
|
+
* Create the list command result
|
|
11
|
+
*/
|
|
12
|
+
export function createListResult(config) {
|
|
13
|
+
if (!config) {
|
|
14
|
+
return {
|
|
15
|
+
success: false,
|
|
16
|
+
error: 'No configuration found. Create a .cli-agent.json file to define commands.',
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const data = {
|
|
20
|
+
name: config.name ?? 'cli-agent',
|
|
21
|
+
description: config.description,
|
|
22
|
+
version: config.version,
|
|
23
|
+
commands: config.commands.map((cmd) => ({
|
|
24
|
+
name: cmd.name,
|
|
25
|
+
description: cmd.description,
|
|
26
|
+
script: cmd.script,
|
|
27
|
+
arguments: cmd.arguments,
|
|
28
|
+
options: cmd.options,
|
|
29
|
+
})),
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
success: true,
|
|
33
|
+
message: `Found ${config.commands.length} command(s)`,
|
|
34
|
+
data,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Format list output for human display
|
|
39
|
+
*/
|
|
40
|
+
export function formatListHuman(config) {
|
|
41
|
+
const lines = [];
|
|
42
|
+
lines.push(`Commands available in ${config.name ?? 'cli-agent'}:`);
|
|
43
|
+
lines.push('');
|
|
44
|
+
if (config.commands.length === 0) {
|
|
45
|
+
lines.push(' No commands defined.');
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// Find longest command name for alignment
|
|
49
|
+
const maxNameLength = Math.max(...config.commands.map((c) => c.name.length));
|
|
50
|
+
for (const cmd of config.commands) {
|
|
51
|
+
const padding = ' '.repeat(maxNameLength - cmd.name.length + 2);
|
|
52
|
+
const description = cmd.description ?? 'No description';
|
|
53
|
+
lines.push(` ${cmd.name}${padding}${description}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
lines.push('');
|
|
57
|
+
lines.push('Use "cli-agent <command> --help" for more information about a command.');
|
|
58
|
+
lines.push('Use "cli-agent list --format json" for machine-readable output.');
|
|
59
|
+
return lines.join('\n');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create the list command
|
|
63
|
+
*/
|
|
64
|
+
export function createListCommand(config) {
|
|
65
|
+
const command = new Command('list');
|
|
66
|
+
command
|
|
67
|
+
.description('List all available commands')
|
|
68
|
+
.option('--format <format>', 'Output format: human or json', 'human')
|
|
69
|
+
.action((options) => {
|
|
70
|
+
const format = options.format === 'json' ? 'json' : 'human';
|
|
71
|
+
if (!config) {
|
|
72
|
+
const result = createListResult(null);
|
|
73
|
+
outputResult(result, format);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (format === 'json') {
|
|
78
|
+
const result = createListResult(config);
|
|
79
|
+
outputResult(result, format);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.log(formatListHuman(config));
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return command;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=list.command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.command.js","sourceRoot":"","sources":["../../../src/cli/commands/list.command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AA6BrD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAwB;IACvD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,2EAA2E;SACnF,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAoB;QAC5B,IAAI,EAAE,MAAM,CAAC,IAAI,I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CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Serve Command
|
|
3
|
+
*
|
|
4
|
+
* Built-in command that starts an MCP server exposing all configured
|
|
5
|
+
* cli-agent commands as MCP tools for Claude Code and other MCP clients.
|
|
6
|
+
*/
|
|
7
|
+
import { Command } from "commander";
|
|
8
|
+
import type { CliConfig } from "../../config/config-schema.js";
|
|
9
|
+
/**
|
|
10
|
+
* Create the mcp:serve command
|
|
11
|
+
*/
|
|
12
|
+
export declare function createMcpServeCommand(config: CliConfig | null, configDir: string | null): Command;
|
|
13
|
+
//# sourceMappingURL=mcp-serve.command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-serve.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/mcp-serve.command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,GAAG,IAAI,EACxB,SAAS,EAAE,MAAM,GAAG,IAAI,GACvB,OAAO,CAsCT"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Serve Command
|
|
3
|
+
*
|
|
4
|
+
* Built-in command that starts an MCP server exposing all configured
|
|
5
|
+
* cli-agent commands as MCP tools for Claude Code and other MCP clients.
|
|
6
|
+
*/
|
|
7
|
+
import { Command } from "commander";
|
|
8
|
+
import { startMcpServer } from "../../mcp/mcp-server.js";
|
|
9
|
+
/**
|
|
10
|
+
* Create the mcp:serve command
|
|
11
|
+
*/
|
|
12
|
+
export function createMcpServeCommand(config, configDir) {
|
|
13
|
+
const command = new Command("mcp:serve");
|
|
14
|
+
command
|
|
15
|
+
.description("Start MCP server exposing all commands as tools")
|
|
16
|
+
.action(async () => {
|
|
17
|
+
if (!config) {
|
|
18
|
+
console.error("Error: No configuration found. Create a .cli-agent.json file to define commands.");
|
|
19
|
+
process.exit(1);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (config.commands.length === 0) {
|
|
23
|
+
console.error("Error: No commands defined in configuration.");
|
|
24
|
+
process.exit(1);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!configDir) {
|
|
28
|
+
console.error("Error: Configuration directory not available.");
|
|
29
|
+
process.exit(1);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
await startMcpServer({ config, configDir });
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error("Error starting MCP server:", error instanceof Error ? error.message : String(error));
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return command;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=mcp-serve.command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-serve.command.js","sourceRoot":"","sources":["../../../src/cli/commands/mcp-serve.command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAwB,EACxB,SAAwB;IAExB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAEzC,OAAO;SACJ,WAAW,CAAC,iDAAiD,CAAC;SAC9D,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CACX,kFAAkF,CACnF,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO;QACT,CAAC;QAED,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;YAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAC/D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,cAAc,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,4BAA4B,EAC5B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA;;;;GAIG"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI Entry Point
|
|
4
|
+
*
|
|
5
|
+
* MCP server that turns your scripts into AI-powered tools.
|
|
6
|
+
*/
|
|
7
|
+
import { Command } from "commander";
|
|
8
|
+
import { loadConfig, getExplicitConfigPath } from "../config/config-loader.js";
|
|
9
|
+
import { createDynamicCommand } from "../command/dynamic-command.factory.js";
|
|
10
|
+
import { createListCommand } from "./commands/list.command.js";
|
|
11
|
+
import { createMcpServeCommand } from "./commands/mcp-serve.command.js";
|
|
12
|
+
import { logError, logDebug } from "../infra/logger.js";
|
|
13
|
+
// Package info
|
|
14
|
+
const VERSION = "2.0.0";
|
|
15
|
+
const DEFAULT_NAME = "cli-agent";
|
|
16
|
+
const DEFAULT_DESCRIPTION = "MCP server that turns your scripts into AI-powered tools";
|
|
17
|
+
/**
|
|
18
|
+
* Create and configure the main CLI program
|
|
19
|
+
*/
|
|
20
|
+
async function createProgram() {
|
|
21
|
+
const program = new Command();
|
|
22
|
+
// Try to load configuration
|
|
23
|
+
const explicitPath = getExplicitConfigPath();
|
|
24
|
+
const configResult = await loadConfig(explicitPath);
|
|
25
|
+
const config = configResult?.config ?? null;
|
|
26
|
+
if (configResult) {
|
|
27
|
+
const { config, configDir, configPath } = configResult;
|
|
28
|
+
program
|
|
29
|
+
.name(config.name ?? DEFAULT_NAME)
|
|
30
|
+
.description(config.description ?? DEFAULT_DESCRIPTION)
|
|
31
|
+
.version(config.version ?? VERSION, "-v, --version", "Output the current version");
|
|
32
|
+
// Register all commands from configuration
|
|
33
|
+
for (const commandConfig of config.commands) {
|
|
34
|
+
const command = createDynamicCommand(commandConfig, configDir);
|
|
35
|
+
program.addCommand(command);
|
|
36
|
+
}
|
|
37
|
+
logDebug("Loaded configuration", {
|
|
38
|
+
path: configPath,
|
|
39
|
+
commandCount: config.commands.length,
|
|
40
|
+
commands: config.commands.map((c) => c.name),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// No configuration found - show helpful message
|
|
45
|
+
program
|
|
46
|
+
.name(DEFAULT_NAME)
|
|
47
|
+
.description(DEFAULT_DESCRIPTION)
|
|
48
|
+
.version(VERSION, "-v, --version", "Output the current version");
|
|
49
|
+
program.addHelpText("after", `
|
|
50
|
+
No configuration file found. Create one of:
|
|
51
|
+
- .cli-agent.json in your project
|
|
52
|
+
- "cli-agent" field in package.json
|
|
53
|
+
- ~/.cli-agent.json for global commands
|
|
54
|
+
|
|
55
|
+
Example .cli-agent.json:
|
|
56
|
+
{
|
|
57
|
+
"name": "my-cli",
|
|
58
|
+
"commands": [
|
|
59
|
+
{
|
|
60
|
+
"name": "hello",
|
|
61
|
+
"description": "Say hello",
|
|
62
|
+
"script": "./scripts/hello.js",
|
|
63
|
+
"options": [
|
|
64
|
+
{ "flags": "-n, --name <name>", "description": "Name to greet" }
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
Example script (./scripts/hello.js):
|
|
71
|
+
export default async function(context) {
|
|
72
|
+
const name = context.options.name || 'World';
|
|
73
|
+
return {
|
|
74
|
+
success: true,
|
|
75
|
+
message: \`Hello, \${name}!\`
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
`);
|
|
79
|
+
}
|
|
80
|
+
// Add built-in commands (always available)
|
|
81
|
+
program.addCommand(createListCommand(config));
|
|
82
|
+
program.addCommand(createMcpServeCommand(config, configResult?.configDir ?? null));
|
|
83
|
+
// Add global options
|
|
84
|
+
program
|
|
85
|
+
.option("-c, --config <path>", "Path to configuration file")
|
|
86
|
+
.helpOption("-h, --help", "Display help for command");
|
|
87
|
+
return program;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Main entry point
|
|
91
|
+
*/
|
|
92
|
+
async function main() {
|
|
93
|
+
try {
|
|
94
|
+
const program = await createProgram();
|
|
95
|
+
await program.parseAsync(process.argv);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
logError("Unexpected error:", error);
|
|
99
|
+
// Output error in JSON format if possible
|
|
100
|
+
if (process.argv.includes("--format") && process.argv.includes("json")) {
|
|
101
|
+
console.log(JSON.stringify({
|
|
102
|
+
success: false,
|
|
103
|
+
error: error instanceof Error ? error.message : String(error),
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Run the CLI
|
|
110
|
+
main();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AK,EAAE,CAAC;QACf,QAAQ,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;QAErC,0CAA0C;QAC1C,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACvE,OAAO,CAAC,GAAG,CACT,IAAI,CAAC,SAAS,CAAC;gBACb,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9D,CAAC,CACH,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,cAAc;AACd,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic Command Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates Commander.js commands from configuration.
|
|
5
|
+
*/
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
import type { CommandConfig } from "../config/config-schema.js";
|
|
8
|
+
/**
|
|
9
|
+
* Create a Commander command from configuration
|
|
10
|
+
*
|
|
11
|
+
* @param config - Command configuration from CLI config file
|
|
12
|
+
* @param configDir - Directory containing the configuration file
|
|
13
|
+
* @returns Configured Commander command
|
|
14
|
+
*/
|
|
15
|
+
export declare function createDynamicCommand(config: CommandConfig, configDir: string): Command;
|
|
16
|
+
//# sourceMappingURL=dynamic-command.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-command.factory.d.ts","sourceRoot":"","sources":["../../src/command/dynamic-command.factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,4BAA4B,CAAC;AAShF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,MAAM,GAChB,OAAO,CAiHT"}
|