@nicolasmondain/cli-agent 2.1.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 +484 -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-manifest.command.d.ts +14 -0
- package/dist/cli/commands/mcp-manifest.command.d.ts.map +1 -0
- package/dist/cli/commands/mcp-manifest.command.js +87 -0
- package/dist/cli/commands/mcp-manifest.command.js.map +1 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +112 -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 +153 -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 +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -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/manifest-generator.d.ts +51 -0
- package/dist/mcp/manifest-generator.d.ts.map +1 -0
- package/dist/mcp/manifest-generator.js +130 -0
- package/dist/mcp/manifest-generator.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 +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
# cli-agent
|
|
2
|
+
|
|
3
|
+
> Bridge the gap between natural language and CLI commands
|
|
4
|
+
|
|
5
|
+
A CLI wrapper that enables AI agents to discover and execute commands through a semantic catalog. Define your commands once in JSON, and let both humans and AI agents use them seamlessly.
|
|
6
|
+
|
|
7
|
+
## Why cli-agent?
|
|
8
|
+
|
|
9
|
+
### The Problem
|
|
10
|
+
|
|
11
|
+
AI agents can execute scripts, but they face challenges:
|
|
12
|
+
|
|
13
|
+
- **Discovery**: They must read source code to understand what scripts exist
|
|
14
|
+
- **Invocation**: They must guess arguments and options
|
|
15
|
+
- **Parsing**: Each script outputs data differently
|
|
16
|
+
|
|
17
|
+
### The Solution
|
|
18
|
+
|
|
19
|
+
cli-agent provides a **semantic catalog** of commands:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
23
|
+
│ "Create a feature folder called user-profile" │ Natural Language
|
|
24
|
+
└─────────────────────────────────────────────────────────────┘
|
|
25
|
+
│
|
|
26
|
+
▼
|
|
27
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
28
|
+
│ .cli-agent.json │
|
|
29
|
+
│ { │
|
|
30
|
+
│ "commands": [{ │
|
|
31
|
+
│ "name": "feature-folder", │
|
|
32
|
+
│ "description": "Generate a new feature folder...", │ Semantic Catalog
|
|
33
|
+
│ "arguments": [{ "name": "name", ... }] │
|
|
34
|
+
│ }] │
|
|
35
|
+
│ } │
|
|
36
|
+
└─────────────────────────────────────────────────────────────┘
|
|
37
|
+
│
|
|
38
|
+
▼
|
|
39
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
40
|
+
│ cli-agent feature-folder user-profile --format json │ CLI Command
|
|
41
|
+
└─────────────────────────────────────────────────────────────┘
|
|
42
|
+
│
|
|
43
|
+
▼
|
|
44
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
45
|
+
│ {"success": true, "data": {"path": "./src/features/..."}} │ Structured Output
|
|
46
|
+
└─────────────────────────────────────────────────────────────┘
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- **Natural Language Mapping** — Command descriptions enable AI agents to match user intent to the right command
|
|
52
|
+
- **Command Discovery** — `cli-agent list --format json` exposes all commands with their arguments and options
|
|
53
|
+
- **MCP Integration** — Generate MCP tool manifests for native Claude Code integration
|
|
54
|
+
- **Multi-runtime Support** — Execute JavaScript, TypeScript, and shell scripts
|
|
55
|
+
- **AI-First Design** — JSON output, non-interactive execution, predictable exit codes
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install @nicolasmondain/cli-agent
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Or globally:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install -g @nicolasmondain/cli-agent
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Quick Start
|
|
70
|
+
|
|
71
|
+
### 1. Create a configuration file
|
|
72
|
+
|
|
73
|
+
Create `.cli-agent.json` in your project root:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"name": "my-cli",
|
|
78
|
+
"description": "My project automation tools",
|
|
79
|
+
"commands": [
|
|
80
|
+
{
|
|
81
|
+
"name": "feature-folder",
|
|
82
|
+
"description": "Generate a new feature folder with component, hook, test, and type files",
|
|
83
|
+
"script": "./scripts/generate-feature.js",
|
|
84
|
+
"arguments": [
|
|
85
|
+
{
|
|
86
|
+
"name": "name",
|
|
87
|
+
"description": "Feature name (e.g., 'user-profile', 'checkout')",
|
|
88
|
+
"required": true
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
"options": [
|
|
92
|
+
{
|
|
93
|
+
"flags": "-p, --path <path>",
|
|
94
|
+
"description": "Base path where to create the feature",
|
|
95
|
+
"default": "./src/features"
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 2. Create your script
|
|
104
|
+
|
|
105
|
+
Create `scripts/generate-feature.js`:
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
export default async function(context) {
|
|
109
|
+
const name = context.args.name;
|
|
110
|
+
const path = context.options.path;
|
|
111
|
+
|
|
112
|
+
// Your logic here...
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
success: true,
|
|
116
|
+
message: `Created feature: ${name}`,
|
|
117
|
+
data: {
|
|
118
|
+
name,
|
|
119
|
+
path: `${path}/${name}`,
|
|
120
|
+
files: ['index.ts', 'component.tsx', 'hook.ts', 'types.ts']
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 3. Run your command
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Human-friendly output
|
|
130
|
+
cli-agent feature-folder user-profile
|
|
131
|
+
|
|
132
|
+
# JSON output for AI agents
|
|
133
|
+
cli-agent feature-folder user-profile --format json
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Command Discovery
|
|
137
|
+
|
|
138
|
+
### For Humans
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# Show all commands
|
|
142
|
+
cli-agent list
|
|
143
|
+
|
|
144
|
+
# Show help for a specific command
|
|
145
|
+
cli-agent feature-folder --help
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### For AI Agents
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Get machine-readable command catalog
|
|
152
|
+
cli-agent list --format json
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Output:
|
|
156
|
+
```json
|
|
157
|
+
{
|
|
158
|
+
"success": true,
|
|
159
|
+
"data": {
|
|
160
|
+
"name": "my-cli",
|
|
161
|
+
"commands": [
|
|
162
|
+
{
|
|
163
|
+
"name": "feature-folder",
|
|
164
|
+
"description": "Generate a new feature folder with component, hook, test, and type files",
|
|
165
|
+
"arguments": [{ "name": "name", "description": "Feature name", "required": true }],
|
|
166
|
+
"options": [{ "flags": "-p, --path <path>", "description": "Base path", "default": "./src/features" }]
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### For MCP Clients
|
|
174
|
+
|
|
175
|
+
Generate an MCP tool manifest for Claude Code and other MCP-compatible clients:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Output to stdout
|
|
179
|
+
cli-agent mcp:manifest
|
|
180
|
+
|
|
181
|
+
# Write to file
|
|
182
|
+
cli-agent mcp:manifest --output .mcp-tools.json
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Output:
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
188
|
+
"tools": [
|
|
189
|
+
{
|
|
190
|
+
"name": "feature-folder",
|
|
191
|
+
"description": "Generate a new feature folder with component, hook, test, and type files",
|
|
192
|
+
"inputSchema": {
|
|
193
|
+
"type": "object",
|
|
194
|
+
"properties": {
|
|
195
|
+
"name": { "type": "string", "description": "Feature name" },
|
|
196
|
+
"path": { "type": "string", "description": "Base path", "default": "./src/features" }
|
|
197
|
+
},
|
|
198
|
+
"required": ["name"]
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Configuration Reference
|
|
206
|
+
|
|
207
|
+
### Configuration File Locations
|
|
208
|
+
|
|
209
|
+
cli-agent looks for configuration in this order:
|
|
210
|
+
|
|
211
|
+
1. `--config <path>` flag (explicit path)
|
|
212
|
+
2. `.cli-agent.json` in current directory
|
|
213
|
+
3. `cli-agent` field in `package.json`
|
|
214
|
+
4. `~/.cli-agent.json` (global commands)
|
|
215
|
+
|
|
216
|
+
### Full Schema
|
|
217
|
+
|
|
218
|
+
```json
|
|
219
|
+
{
|
|
220
|
+
"name": "my-cli",
|
|
221
|
+
"version": "1.0.0",
|
|
222
|
+
"description": "CLI description shown in help",
|
|
223
|
+
"commands": [
|
|
224
|
+
{
|
|
225
|
+
"name": "command-name",
|
|
226
|
+
"description": "Clear description for AI agent understanding",
|
|
227
|
+
"script": "./path/to/script.js",
|
|
228
|
+
"arguments": [
|
|
229
|
+
{
|
|
230
|
+
"name": "arg-name",
|
|
231
|
+
"description": "What this argument represents",
|
|
232
|
+
"required": true,
|
|
233
|
+
"variadic": false
|
|
234
|
+
}
|
|
235
|
+
],
|
|
236
|
+
"options": [
|
|
237
|
+
{
|
|
238
|
+
"flags": "-s, --short <value>",
|
|
239
|
+
"description": "What this option does",
|
|
240
|
+
"default": "default-value",
|
|
241
|
+
"required": false,
|
|
242
|
+
"choices": ["option1", "option2"]
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Writing Effective Descriptions
|
|
251
|
+
|
|
252
|
+
Good descriptions are crucial for AI agents to match user intent:
|
|
253
|
+
|
|
254
|
+
```json
|
|
255
|
+
{
|
|
256
|
+
"name": "feature-folder",
|
|
257
|
+
"description": "Generate a new feature folder with component, hook, test, and type files"
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
```json
|
|
262
|
+
{
|
|
263
|
+
"name": "db:migrate",
|
|
264
|
+
"description": "Run database migrations to update schema to latest version"
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
```json
|
|
269
|
+
{
|
|
270
|
+
"name": "deploy",
|
|
271
|
+
"description": "Deploy the application to the specified environment (staging or production)"
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Writing Scripts
|
|
276
|
+
|
|
277
|
+
### JavaScript Scripts (.js)
|
|
278
|
+
|
|
279
|
+
Scripts must export a default async function:
|
|
280
|
+
|
|
281
|
+
```javascript
|
|
282
|
+
/**
|
|
283
|
+
* @param {import('@nicolasmondain/cli-agent').ScriptContext} context
|
|
284
|
+
* @returns {Promise<import('@nicolasmondain/cli-agent').CommandResult>}
|
|
285
|
+
*/
|
|
286
|
+
export default async function(context) {
|
|
287
|
+
// context.args - positional arguments { name: 'value' }
|
|
288
|
+
// context.options - command options { path: './src', verbose: true }
|
|
289
|
+
// context.cwd - current working directory
|
|
290
|
+
// context.format - 'human' or 'json'
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
success: true,
|
|
294
|
+
message: 'Human-readable message',
|
|
295
|
+
data: { /* structured data */ }
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### TypeScript Scripts (.ts)
|
|
301
|
+
|
|
302
|
+
TypeScript scripts are executed via `tsx` or `ts-node`:
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
import type { ScriptContext, CommandResult } from '@nicolasmondain/cli-agent';
|
|
306
|
+
|
|
307
|
+
export default async function(context: ScriptContext): Promise<CommandResult> {
|
|
308
|
+
const name = context.args.name as string;
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
success: true,
|
|
312
|
+
message: `Hello, ${name}!`,
|
|
313
|
+
data: { greeting: `Hello, ${name}!` }
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
> **Note:** Install `tsx` for TypeScript support: `npm install -g tsx`
|
|
319
|
+
|
|
320
|
+
### Shell Scripts (.sh)
|
|
321
|
+
|
|
322
|
+
Shell scripts receive context via environment variables:
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
#!/bin/bash
|
|
326
|
+
|
|
327
|
+
# Arguments: CLI_AGENT_ARG_<NAME>
|
|
328
|
+
# Options: CLI_AGENT_OPT_<NAME>
|
|
329
|
+
# Format: CLI_AGENT_FORMAT
|
|
330
|
+
# CWD: CLI_AGENT_CWD
|
|
331
|
+
|
|
332
|
+
NAME="${CLI_AGENT_ARG_NAME}"
|
|
333
|
+
PATH_OPT="${CLI_AGENT_OPT_PATH:-./src/features}"
|
|
334
|
+
|
|
335
|
+
# Output JSON for structured response
|
|
336
|
+
if [ "$CLI_AGENT_FORMAT" = "json" ]; then
|
|
337
|
+
echo "{\"success\": true, \"data\": {\"name\": \"$NAME\", \"path\": \"$PATH_OPT\"}}"
|
|
338
|
+
else
|
|
339
|
+
echo "Created feature: $NAME at $PATH_OPT"
|
|
340
|
+
fi
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## Standard Options
|
|
344
|
+
|
|
345
|
+
All commands automatically have these options:
|
|
346
|
+
|
|
347
|
+
| Option | Description |
|
|
348
|
+
|--------|-------------|
|
|
349
|
+
| `--format <format>` | Output format: `human` or `json` (default: `human`) |
|
|
350
|
+
| `--quiet` | Suppress all output except errors |
|
|
351
|
+
| `--verbose` | Show detailed output |
|
|
352
|
+
| `--debug` | Show debug information |
|
|
353
|
+
|
|
354
|
+
## Built-in Commands
|
|
355
|
+
|
|
356
|
+
| Command | Description |
|
|
357
|
+
|---------|-------------|
|
|
358
|
+
| `list` | List all available commands |
|
|
359
|
+
| `mcp:manifest` | Generate MCP tool manifest |
|
|
360
|
+
|
|
361
|
+
## Using Utilities in Scripts
|
|
362
|
+
|
|
363
|
+
cli-agent exports utility functions for use in your scripts:
|
|
364
|
+
|
|
365
|
+
```javascript
|
|
366
|
+
import {
|
|
367
|
+
// Naming utilities
|
|
368
|
+
toKebabCase,
|
|
369
|
+
toPascalCase,
|
|
370
|
+
toCamelCase,
|
|
371
|
+
toScreamingSnakeCase,
|
|
372
|
+
|
|
373
|
+
// File system utilities
|
|
374
|
+
pathExists,
|
|
375
|
+
createDirectory,
|
|
376
|
+
createFile,
|
|
377
|
+
|
|
378
|
+
// Logging
|
|
379
|
+
logInfo,
|
|
380
|
+
logError,
|
|
381
|
+
logSuccess,
|
|
382
|
+
logWarning,
|
|
383
|
+
} from '@nicolasmondain/cli-agent';
|
|
384
|
+
|
|
385
|
+
export default async function(context) {
|
|
386
|
+
const name = toKebabCase(context.args.name);
|
|
387
|
+
|
|
388
|
+
if (await pathExists(`./${name}`)) {
|
|
389
|
+
return { success: false, error: 'Directory already exists' };
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
await createDirectory(`./${name}`);
|
|
393
|
+
logSuccess(`Created ${name}/`);
|
|
394
|
+
|
|
395
|
+
return { success: true, message: `Created ${name}/` };
|
|
396
|
+
}
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
## Example: Complete Feature Generator
|
|
400
|
+
|
|
401
|
+
`.cli-agent.json`:
|
|
402
|
+
```json
|
|
403
|
+
{
|
|
404
|
+
"name": "project-cli",
|
|
405
|
+
"commands": [
|
|
406
|
+
{
|
|
407
|
+
"name": "feature",
|
|
408
|
+
"description": "Generate a new feature folder with React component, custom hook, tests, and TypeScript types",
|
|
409
|
+
"script": "./scripts/generate-feature.js",
|
|
410
|
+
"arguments": [
|
|
411
|
+
{ "name": "name", "description": "Feature name in kebab-case (e.g., 'user-profile')", "required": true }
|
|
412
|
+
],
|
|
413
|
+
"options": [
|
|
414
|
+
{ "flags": "-p, --path <path>", "description": "Base path for features", "default": "./src/features" },
|
|
415
|
+
{ "flags": "--no-test", "description": "Skip test file generation" },
|
|
416
|
+
{ "flags": "--no-hook", "description": "Skip hook file generation" }
|
|
417
|
+
]
|
|
418
|
+
}
|
|
419
|
+
]
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
`scripts/generate-feature.js`:
|
|
424
|
+
```javascript
|
|
425
|
+
import { toKebabCase, toPascalCase, createDirectory, createFile, pathExists } from '@nicolasmondain/cli-agent';
|
|
426
|
+
import { resolve } from 'node:path';
|
|
427
|
+
|
|
428
|
+
export default async function(context) {
|
|
429
|
+
const name = toKebabCase(context.args.name);
|
|
430
|
+
const pascalName = toPascalCase(name);
|
|
431
|
+
const basePath = context.options.path;
|
|
432
|
+
const featurePath = resolve(context.cwd, basePath, name);
|
|
433
|
+
|
|
434
|
+
if (await pathExists(featurePath)) {
|
|
435
|
+
return { success: false, error: `Feature "${name}" already exists at ${featurePath}` };
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const files = [];
|
|
439
|
+
|
|
440
|
+
await createDirectory(featurePath);
|
|
441
|
+
|
|
442
|
+
// Component
|
|
443
|
+
await createFile(`${featurePath}/${pascalName}.tsx`, `export function ${pascalName}() {\n return <div>${pascalName}</div>;\n}\n`);
|
|
444
|
+
files.push(`${pascalName}.tsx`);
|
|
445
|
+
|
|
446
|
+
// Hook
|
|
447
|
+
if (context.options.hook !== false) {
|
|
448
|
+
await createFile(`${featurePath}/use${pascalName}.ts`, `export function use${pascalName}() {\n return {};\n}\n`);
|
|
449
|
+
files.push(`use${pascalName}.ts`);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// Test
|
|
453
|
+
if (context.options.test !== false) {
|
|
454
|
+
await createFile(`${featurePath}/${pascalName}.test.tsx`, `import { ${pascalName} } from './${pascalName}';\n\ndescribe('${pascalName}', () => {\n it('renders', () => {});\n});\n`);
|
|
455
|
+
files.push(`${pascalName}.test.tsx`);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Index
|
|
459
|
+
await createFile(`${featurePath}/index.ts`, `export * from './${pascalName}';\n`);
|
|
460
|
+
files.push('index.ts');
|
|
461
|
+
|
|
462
|
+
return {
|
|
463
|
+
success: true,
|
|
464
|
+
message: `Created feature "${name}" with ${files.length} files`,
|
|
465
|
+
data: { name, path: featurePath, files }
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
## Project Structure
|
|
471
|
+
|
|
472
|
+
```
|
|
473
|
+
your-project/
|
|
474
|
+
├── .cli-agent.json # CLI configuration
|
|
475
|
+
├── scripts/
|
|
476
|
+
│ ├── generate-feature.js # JavaScript script
|
|
477
|
+
│ ├── run-migrations.ts # TypeScript script
|
|
478
|
+
│ └── deploy.sh # Shell script
|
|
479
|
+
└── package.json
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
## License
|
|
483
|
+
|
|
484
|
+
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,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGxE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,KAAK,CAAC;YAChB,IAAI,EAAE,MAAM,CAAC;YACb,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;YACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;SACpB,CAAC,CAAC;QACH,OAAO,CAAC,EAAE,KAAK,CAAC;YACd,KAAK,EAAE,MAAM,CAAC;YACd,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,OAAO,CAAC,EAAE,OAAO,CAAC;YAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;YACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;SACpB,CAAC,CAAC;KACJ,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,GAAG,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC,CA0BhG;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAwBzD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,CAyBnE"}
|
|
@@ -0,0 +1,87 @@
|
|
|
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 { 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,IAAI,WAAW;QAChC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,OAAO,EAAE,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
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Manifest Command
|
|
3
|
+
*
|
|
4
|
+
* Built-in command that generates an MCP (Model Context Protocol) tool manifest
|
|
5
|
+
* from the cli-agent configuration. This enables native integration with
|
|
6
|
+
* Claude Code and other MCP-compatible clients.
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import type { CliConfig } from '../../config/config-schema.js';
|
|
10
|
+
/**
|
|
11
|
+
* Create the mcp:manifest command
|
|
12
|
+
*/
|
|
13
|
+
export declare function createMcpManifestCommand(config: CliConfig | null): Command;
|
|
14
|
+
//# sourceMappingURL=mcp-manifest.command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-manifest.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/mcp-manifest.command.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAK/D;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,CAyF1E"}
|