@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.
Potentially problematic release.
This version of @nicolasmondain/cli-agent might be problematic. Click here for more details.
- 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
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Validator
|
|
3
|
+
*
|
|
4
|
+
* Validates CLI configuration structure.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Validation error with details
|
|
8
|
+
*/
|
|
9
|
+
export class ConfigValidationError extends Error {
|
|
10
|
+
path;
|
|
11
|
+
value;
|
|
12
|
+
constructor(message, path, value) {
|
|
13
|
+
super(`Configuration error at '${path}': ${message}`);
|
|
14
|
+
this.path = path;
|
|
15
|
+
this.value = value;
|
|
16
|
+
this.name = 'ConfigValidationError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validate a configuration object
|
|
21
|
+
* @throws ConfigValidationError if validation fails
|
|
22
|
+
*/
|
|
23
|
+
export function validateConfig(config) {
|
|
24
|
+
if (!config || typeof config !== 'object') {
|
|
25
|
+
throw new ConfigValidationError('Configuration must be an object', 'root', config);
|
|
26
|
+
}
|
|
27
|
+
const cfg = config;
|
|
28
|
+
// Validate optional string fields
|
|
29
|
+
if (cfg.name !== undefined && typeof cfg.name !== 'string') {
|
|
30
|
+
throw new ConfigValidationError('Must be a string', 'name', cfg.name);
|
|
31
|
+
}
|
|
32
|
+
if (cfg.version !== undefined && typeof cfg.version !== 'string') {
|
|
33
|
+
throw new ConfigValidationError('Must be a string', 'version', cfg.version);
|
|
34
|
+
}
|
|
35
|
+
if (cfg.description !== undefined && typeof cfg.description !== 'string') {
|
|
36
|
+
throw new ConfigValidationError('Must be a string', 'description', cfg.description);
|
|
37
|
+
}
|
|
38
|
+
// Validate commands array
|
|
39
|
+
if (!Array.isArray(cfg.commands)) {
|
|
40
|
+
throw new ConfigValidationError('Must be an array', 'commands', cfg.commands);
|
|
41
|
+
}
|
|
42
|
+
const commands = cfg.commands.map((cmd, index) => validateCommand(cmd, `commands[${index}]`));
|
|
43
|
+
return {
|
|
44
|
+
name: cfg.name,
|
|
45
|
+
version: cfg.version,
|
|
46
|
+
description: cfg.description,
|
|
47
|
+
commands,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validate a command configuration
|
|
52
|
+
*/
|
|
53
|
+
function validateCommand(cmd, path) {
|
|
54
|
+
if (!cmd || typeof cmd !== 'object') {
|
|
55
|
+
throw new ConfigValidationError('Must be an object', path, cmd);
|
|
56
|
+
}
|
|
57
|
+
const command = cmd;
|
|
58
|
+
// Required: name
|
|
59
|
+
if (typeof command.name !== 'string' || command.name.trim() === '') {
|
|
60
|
+
throw new ConfigValidationError('Must be a non-empty string', `${path}.name`, command.name);
|
|
61
|
+
}
|
|
62
|
+
// Required: script
|
|
63
|
+
if (typeof command.script !== 'string' || command.script.trim() === '') {
|
|
64
|
+
throw new ConfigValidationError('Must be a non-empty string', `${path}.script`, command.script);
|
|
65
|
+
}
|
|
66
|
+
// Optional: description
|
|
67
|
+
if (command.description !== undefined && typeof command.description !== 'string') {
|
|
68
|
+
throw new ConfigValidationError('Must be a string', `${path}.description`, command.description);
|
|
69
|
+
}
|
|
70
|
+
// Optional: arguments
|
|
71
|
+
let args;
|
|
72
|
+
if (command.arguments !== undefined) {
|
|
73
|
+
if (!Array.isArray(command.arguments)) {
|
|
74
|
+
throw new ConfigValidationError('Must be an array', `${path}.arguments`, command.arguments);
|
|
75
|
+
}
|
|
76
|
+
args = command.arguments.map((arg, index) => validateArgument(arg, `${path}.arguments[${index}]`));
|
|
77
|
+
}
|
|
78
|
+
// Optional: options
|
|
79
|
+
let options;
|
|
80
|
+
if (command.options !== undefined) {
|
|
81
|
+
if (!Array.isArray(command.options)) {
|
|
82
|
+
throw new ConfigValidationError('Must be an array', `${path}.options`, command.options);
|
|
83
|
+
}
|
|
84
|
+
options = command.options.map((opt, index) => validateOption(opt, `${path}.options[${index}]`));
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
name: command.name,
|
|
88
|
+
description: command.description,
|
|
89
|
+
script: command.script,
|
|
90
|
+
arguments: args,
|
|
91
|
+
options,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Validate an argument configuration
|
|
96
|
+
*/
|
|
97
|
+
function validateArgument(arg, path) {
|
|
98
|
+
if (!arg || typeof arg !== 'object') {
|
|
99
|
+
throw new ConfigValidationError('Must be an object', path, arg);
|
|
100
|
+
}
|
|
101
|
+
const argument = arg;
|
|
102
|
+
// Required: name
|
|
103
|
+
if (typeof argument.name !== 'string' || argument.name.trim() === '') {
|
|
104
|
+
throw new ConfigValidationError('Must be a non-empty string', `${path}.name`, argument.name);
|
|
105
|
+
}
|
|
106
|
+
// Optional: description
|
|
107
|
+
if (argument.description !== undefined && typeof argument.description !== 'string') {
|
|
108
|
+
throw new ConfigValidationError('Must be a string', `${path}.description`, argument.description);
|
|
109
|
+
}
|
|
110
|
+
// Optional: required (default: true)
|
|
111
|
+
if (argument.required !== undefined && typeof argument.required !== 'boolean') {
|
|
112
|
+
throw new ConfigValidationError('Must be a boolean', `${path}.required`, argument.required);
|
|
113
|
+
}
|
|
114
|
+
// Optional: variadic (default: false)
|
|
115
|
+
if (argument.variadic !== undefined && typeof argument.variadic !== 'boolean') {
|
|
116
|
+
throw new ConfigValidationError('Must be a boolean', `${path}.variadic`, argument.variadic);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
name: argument.name,
|
|
120
|
+
description: argument.description,
|
|
121
|
+
required: argument.required,
|
|
122
|
+
variadic: argument.variadic,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Validate an option configuration
|
|
127
|
+
*/
|
|
128
|
+
function validateOption(opt, path) {
|
|
129
|
+
if (!opt || typeof opt !== 'object') {
|
|
130
|
+
throw new ConfigValidationError('Must be an object', path, opt);
|
|
131
|
+
}
|
|
132
|
+
const option = opt;
|
|
133
|
+
// Required: flags
|
|
134
|
+
if (typeof option.flags !== 'string' || option.flags.trim() === '') {
|
|
135
|
+
throw new ConfigValidationError('Must be a non-empty string', `${path}.flags`, option.flags);
|
|
136
|
+
}
|
|
137
|
+
// Optional: description
|
|
138
|
+
if (option.description !== undefined && typeof option.description !== 'string') {
|
|
139
|
+
throw new ConfigValidationError('Must be a string', `${path}.description`, option.description);
|
|
140
|
+
}
|
|
141
|
+
// Optional: required
|
|
142
|
+
if (option.required !== undefined && typeof option.required !== 'boolean') {
|
|
143
|
+
throw new ConfigValidationError('Must be a boolean', `${path}.required`, option.required);
|
|
144
|
+
}
|
|
145
|
+
// Optional: choices
|
|
146
|
+
if (option.choices !== undefined) {
|
|
147
|
+
if (!Array.isArray(option.choices)) {
|
|
148
|
+
throw new ConfigValidationError('Must be an array', `${path}.choices`, option.choices);
|
|
149
|
+
}
|
|
150
|
+
if (!option.choices.every((c) => typeof c === 'string')) {
|
|
151
|
+
throw new ConfigValidationError('All choices must be strings', `${path}.choices`, option.choices);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
flags: option.flags,
|
|
156
|
+
description: option.description,
|
|
157
|
+
default: option.default,
|
|
158
|
+
required: option.required,
|
|
159
|
+
choices: option.choices,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=config-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-validator.js","sourceRoot":"","sources":["../../src/config/config-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAG5B;IACA;IAHlB,YACE,OAAe,EACC,IAAY,EACZ,KAAe;QAE/B,KAAK,CAAC,2BAA2B,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC;QAHtC,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAU;QAG/B,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAe;IAC5C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,MAAM,IAAI,qBAAqB,CAAC,iCAAiC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACrF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ACrD,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,QAAQ,EAAE,MAAM,CAAC,QAA+B;QAChD,OAAO,EAAE,MAAM,CAAC,OAA+B;KAChD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript Executor
|
|
3
|
+
*
|
|
4
|
+
* Executes .js files by importing and calling their default export.
|
|
5
|
+
*/
|
|
6
|
+
import type { ScriptContext, ScriptResult } from './script-executor.js';
|
|
7
|
+
/**
|
|
8
|
+
* Execute a JavaScript file
|
|
9
|
+
*
|
|
10
|
+
* The script must export a default async function that accepts ScriptContext
|
|
11
|
+
* and returns a CommandResult.
|
|
12
|
+
*
|
|
13
|
+
* Example script:
|
|
14
|
+
* ```javascript
|
|
15
|
+
* export default async function(context) {
|
|
16
|
+
* return {
|
|
17
|
+
* success: true,
|
|
18
|
+
* message: 'Hello!',
|
|
19
|
+
* data: { greeting: 'Hello!' }
|
|
20
|
+
* };
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param scriptPath - Absolute path to the JavaScript file
|
|
25
|
+
* @param context - Execution context
|
|
26
|
+
* @returns Script execution result
|
|
27
|
+
*/
|
|
28
|
+
export declare function executeJavaScript(scriptPath: string, context: ScriptContext): Promise<ScriptResult>;
|
|
29
|
+
//# sourceMappingURL=js-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-executor.d.ts","sourceRoot":"","sources":["../../src/executor/js-executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGxE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CA2CvB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript Executor
|
|
3
|
+
*
|
|
4
|
+
* Executes .js files by importing and calling their default export.
|
|
5
|
+
*/
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
import { pathExists } from '../services/file-system.service.js';
|
|
8
|
+
/**
|
|
9
|
+
* Execute a JavaScript file
|
|
10
|
+
*
|
|
11
|
+
* The script must export a default async function that accepts ScriptContext
|
|
12
|
+
* and returns a CommandResult.
|
|
13
|
+
*
|
|
14
|
+
* Example script:
|
|
15
|
+
* ```javascript
|
|
16
|
+
* export default async function(context) {
|
|
17
|
+
* return {
|
|
18
|
+
* success: true,
|
|
19
|
+
* message: 'Hello!',
|
|
20
|
+
* data: { greeting: 'Hello!' }
|
|
21
|
+
* };
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param scriptPath - Absolute path to the JavaScript file
|
|
26
|
+
* @param context - Execution context
|
|
27
|
+
* @returns Script execution result
|
|
28
|
+
*/
|
|
29
|
+
export async function executeJavaScript(scriptPath, context) {
|
|
30
|
+
try {
|
|
31
|
+
// Check if file exists
|
|
32
|
+
if (!(await pathExists(scriptPath))) {
|
|
33
|
+
return {
|
|
34
|
+
success: false,
|
|
35
|
+
error: `Script not found: ${scriptPath}`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Use dynamic import with file URL for cross-platform compatibility
|
|
39
|
+
const scriptUrl = pathToFileURL(scriptPath).href;
|
|
40
|
+
// Add cache busting to allow re-importing modified scripts
|
|
41
|
+
const urlWithCacheBust = `${scriptUrl}?t=${Date.now()}`;
|
|
42
|
+
const module = await import(urlWithCacheBust);
|
|
43
|
+
// Check for default export
|
|
44
|
+
if (typeof module.default !== 'function') {
|
|
45
|
+
return {
|
|
46
|
+
success: false,
|
|
47
|
+
error: `Script must export a default function: ${scriptPath}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Execute the script
|
|
51
|
+
const result = await module.default(context);
|
|
52
|
+
// Validate result structure
|
|
53
|
+
if (!isValidResult(result)) {
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
56
|
+
error: `Script must return an object with a 'success' boolean property: ${scriptPath}`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
error: `Script execution failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check if result has required structure
|
|
70
|
+
*/
|
|
71
|
+
function isValidResult(result) {
|
|
72
|
+
return (result !== null &&
|
|
73
|
+
typeof result === 'object' &&
|
|
74
|
+
'success' in result &&
|
|
75
|
+
typeof result.success === 'boolean');
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=js-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-executor.js","sourceRoot":"","sources":["../../src/executor/js-executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,UAAkB,EAClB,OAAsB;IAEtB,IAAI,CAAC;QACH,uBAAuB;QACvB,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YACpC,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,qBAAqB,UAAU,EAAE;aACzC,CAAC;QACJ,CAAC;QAED,oEAAoE;QACpE,MAAM,SAAS,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QAEjD,2DAA2D;QAC3D,MAAM,gBAAgB,GAAG,GAAG,SAAS,MAAM,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QACxD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAE9C,2BAA2B;QAC3B,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;YACzC,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,0CAA0C,UAAU,EAAE;aAC9D,CAAC;QACJ,CAAC;QAED,qBAAqB;QACrB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE7C,4BAA4B;QAC5B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,mEAAmE,UAAU,EAAE;aACvF,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,4BAA4B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;SAC5F,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,MAAe;IACpC,OAAO,CACL,MAAM,KAAK,IAAI;QACf,OAAO,MAAM,KAAK,QAAQ;QAC1B,SAAS,IAAI,MAAM;QACnB,OAAQ,MAAuB,CAAC,OAAO,KAAK,SAAS,CACtD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Script Executor
|
|
3
|
+
*
|
|
4
|
+
* Executes external scripts (.js, .ts, .sh) and handles output.
|
|
5
|
+
*/
|
|
6
|
+
import type { CommandResult, OutputFormat } from '../types/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Context passed to scripts during execution
|
|
9
|
+
*/
|
|
10
|
+
export interface ScriptContext {
|
|
11
|
+
/** Parsed positional arguments */
|
|
12
|
+
args: Record<string, unknown>;
|
|
13
|
+
/** Parsed options */
|
|
14
|
+
options: Record<string, unknown>;
|
|
15
|
+
/** Current working directory */
|
|
16
|
+
cwd: string;
|
|
17
|
+
/** Output format requested */
|
|
18
|
+
format: OutputFormat;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Result from script execution
|
|
22
|
+
*/
|
|
23
|
+
export type ScriptResult = CommandResult<unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Execute a script file based on its extension
|
|
26
|
+
*
|
|
27
|
+
* @param scriptPath - Path to the script (relative to configDir)
|
|
28
|
+
* @param context - Execution context with args and options
|
|
29
|
+
* @param configDir - Directory containing the configuration file
|
|
30
|
+
* @returns Script execution result
|
|
31
|
+
*/
|
|
32
|
+
export declare function executeScript(scriptPath: string, context: ScriptContext, configDir: string): Promise<ScriptResult>;
|
|
33
|
+
//# sourceMappingURL=script-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-executor.d.ts","sourceRoot":"","sources":["../../src/executor/script-executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKrE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,MAAM,EAAE,YAAY,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AASlD;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,YAAY,CAAC,CAwBvB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Script Executor
|
|
3
|
+
*
|
|
4
|
+
* Executes external scripts (.js, .ts, .sh) and handles output.
|
|
5
|
+
*/
|
|
6
|
+
import { resolve, extname } from 'node:path';
|
|
7
|
+
import { executeJavaScript } from './js-executor.js';
|
|
8
|
+
import { executeTypeScript } from './ts-executor.js';
|
|
9
|
+
import { executeShell } from './shell-executor.js';
|
|
10
|
+
/**
|
|
11
|
+
* Supported script extensions
|
|
12
|
+
*/
|
|
13
|
+
const JAVASCRIPT_EXTENSIONS = ['.js', '.mjs', '.cjs'];
|
|
14
|
+
const TYPESCRIPT_EXTENSIONS = ['.ts', '.mts', '.cts'];
|
|
15
|
+
const SHELL_EXTENSIONS = ['.sh'];
|
|
16
|
+
/**
|
|
17
|
+
* Execute a script file based on its extension
|
|
18
|
+
*
|
|
19
|
+
* @param scriptPath - Path to the script (relative to configDir)
|
|
20
|
+
* @param context - Execution context with args and options
|
|
21
|
+
* @param configDir - Directory containing the configuration file
|
|
22
|
+
* @returns Script execution result
|
|
23
|
+
*/
|
|
24
|
+
export async function executeScript(scriptPath, context, configDir) {
|
|
25
|
+
const absolutePath = resolve(configDir, scriptPath);
|
|
26
|
+
const ext = extname(absolutePath).toLowerCase();
|
|
27
|
+
if (JAVASCRIPT_EXTENSIONS.includes(ext)) {
|
|
28
|
+
return executeJavaScript(absolutePath, context);
|
|
29
|
+
}
|
|
30
|
+
if (TYPESCRIPT_EXTENSIONS.includes(ext)) {
|
|
31
|
+
return executeTypeScript(absolutePath, context);
|
|
32
|
+
}
|
|
33
|
+
if (SHELL_EXTENSIONS.includes(ext)) {
|
|
34
|
+
return executeShell(absolutePath, context);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
success: false,
|
|
38
|
+
error: `Unsupported script type: ${ext}. Supported: ${[
|
|
39
|
+
...JAVASCRIPT_EXTENSIONS,
|
|
40
|
+
...TYPESCRIPT_EXTENSIONS,
|
|
41
|
+
...SHELL_EXTENSIONS,
|
|
42
|
+
].join(', ')}`,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=script-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-executor.js","sourceRoot":"","sources":["../../src/executor/script-executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAqBnD;;GAEG;AACH,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACtD,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACtD,MAAM,gBAAgB,GAAG,CAAC,KAAK,CAAC,CAAC;AAEjC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,UAAkB,EAClB,OAAsB,EACtB,SAAiB;IAEjB,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC;IAEhD,IAAI,qBAAqB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxC,OAAO,iBAAiB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,qBAAqB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxC,OAAO,iBAAiB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,OAAO,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,4BAA4B,GAAG,gBAAgB;YACpD,GAAG,qBAAqB;YACxB,GAAG,qBAAqB;YACxB,GAAG,gBAAgB;SACpB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;KACf,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell Executor
|
|
3
|
+
*
|
|
4
|
+
* Executes .sh files using the system shell.
|
|
5
|
+
*/
|
|
6
|
+
import type { ScriptContext, ScriptResult } from './script-executor.js';
|
|
7
|
+
/**
|
|
8
|
+
* Execute a shell script
|
|
9
|
+
*
|
|
10
|
+
* Arguments and options are passed as environment variables:
|
|
11
|
+
* - CLI_AGENT_ARG_<NAME> for arguments (uppercase, underscores)
|
|
12
|
+
* - CLI_AGENT_OPT_<NAME> for options (uppercase, underscores)
|
|
13
|
+
* - CLI_AGENT_FORMAT for output format
|
|
14
|
+
* - CLI_AGENT_CWD for current working directory
|
|
15
|
+
*
|
|
16
|
+
* Example script:
|
|
17
|
+
* ```bash
|
|
18
|
+
* #!/bin/bash
|
|
19
|
+
* echo "Name: $CLI_AGENT_OPT_NAME"
|
|
20
|
+
* echo "Format: $CLI_AGENT_FORMAT"
|
|
21
|
+
*
|
|
22
|
+
* # For JSON output:
|
|
23
|
+
* if [ "$CLI_AGENT_FORMAT" = "json" ]; then
|
|
24
|
+
* echo '{"success": true, "message": "Done!"}'
|
|
25
|
+
* fi
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param scriptPath - Absolute path to the shell script
|
|
29
|
+
* @param context - Execution context
|
|
30
|
+
* @returns Script execution result
|
|
31
|
+
*/
|
|
32
|
+
export declare function executeShell(scriptPath: string, context: ScriptContext): Promise<ScriptResult>;
|
|
33
|
+
//# sourceMappingURL=shell-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-executor.d.ts","sourceRoot":"","sources":["../../src/executor/shell-executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGxE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CA+FvB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell Executor
|
|
3
|
+
*
|
|
4
|
+
* Executes .sh files using the system shell.
|
|
5
|
+
*/
|
|
6
|
+
import { spawn } from 'node:child_process';
|
|
7
|
+
import { pathExists } from '../services/file-system.service.js';
|
|
8
|
+
/**
|
|
9
|
+
* Execute a shell script
|
|
10
|
+
*
|
|
11
|
+
* Arguments and options are passed as environment variables:
|
|
12
|
+
* - CLI_AGENT_ARG_<NAME> for arguments (uppercase, underscores)
|
|
13
|
+
* - CLI_AGENT_OPT_<NAME> for options (uppercase, underscores)
|
|
14
|
+
* - CLI_AGENT_FORMAT for output format
|
|
15
|
+
* - CLI_AGENT_CWD for current working directory
|
|
16
|
+
*
|
|
17
|
+
* Example script:
|
|
18
|
+
* ```bash
|
|
19
|
+
* #!/bin/bash
|
|
20
|
+
* echo "Name: $CLI_AGENT_OPT_NAME"
|
|
21
|
+
* echo "Format: $CLI_AGENT_FORMAT"
|
|
22
|
+
*
|
|
23
|
+
* # For JSON output:
|
|
24
|
+
* if [ "$CLI_AGENT_FORMAT" = "json" ]; then
|
|
25
|
+
* echo '{"success": true, "message": "Done!"}'
|
|
26
|
+
* fi
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param scriptPath - Absolute path to the shell script
|
|
30
|
+
* @param context - Execution context
|
|
31
|
+
* @returns Script execution result
|
|
32
|
+
*/
|
|
33
|
+
export async function executeShell(scriptPath, context) {
|
|
34
|
+
// Check if file exists
|
|
35
|
+
if (!(await pathExists(scriptPath))) {
|
|
36
|
+
return {
|
|
37
|
+
success: false,
|
|
38
|
+
error: `Script not found: ${scriptPath}`,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
// Build environment variables from context
|
|
43
|
+
const env = { ...process.env };
|
|
44
|
+
// Add arguments as CLI_AGENT_ARG_<NAME>
|
|
45
|
+
for (const [key, value] of Object.entries(context.args)) {
|
|
46
|
+
if (value !== undefined && value !== null) {
|
|
47
|
+
env[`CLI_AGENT_ARG_${toEnvName(key)}`] = String(value);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Add options as CLI_AGENT_OPT_<NAME>
|
|
51
|
+
for (const [key, value] of Object.entries(context.options)) {
|
|
52
|
+
if (value !== undefined && value !== null) {
|
|
53
|
+
// Handle boolean options
|
|
54
|
+
if (typeof value === 'boolean') {
|
|
55
|
+
env[`CLI_AGENT_OPT_${toEnvName(key)}`] = value ? 'true' : 'false';
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
env[`CLI_AGENT_OPT_${toEnvName(key)}`] = String(value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Add standard context variables
|
|
63
|
+
env.CLI_AGENT_FORMAT = context.format;
|
|
64
|
+
env.CLI_AGENT_CWD = context.cwd;
|
|
65
|
+
// Spawn bash with the script
|
|
66
|
+
const child = spawn('bash', [scriptPath], {
|
|
67
|
+
env,
|
|
68
|
+
cwd: context.cwd,
|
|
69
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
70
|
+
});
|
|
71
|
+
let stdout = '';
|
|
72
|
+
let stderr = '';
|
|
73
|
+
child.stdout?.on('data', (data) => {
|
|
74
|
+
stdout += data.toString();
|
|
75
|
+
});
|
|
76
|
+
child.stderr?.on('data', (data) => {
|
|
77
|
+
stderr += data.toString();
|
|
78
|
+
});
|
|
79
|
+
child.on('error', (error) => {
|
|
80
|
+
resolve({
|
|
81
|
+
success: false,
|
|
82
|
+
error: `Failed to execute shell script: ${error.message}`,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
child.on('close', (code) => {
|
|
86
|
+
// Try to parse JSON output from script
|
|
87
|
+
const trimmedStdout = stdout.trim();
|
|
88
|
+
// Look for JSON in the last line (scripts might output logs before JSON)
|
|
89
|
+
const lines = trimmedStdout.split('\n');
|
|
90
|
+
const lastLine = lines[lines.length - 1]?.trim() || '';
|
|
91
|
+
if (lastLine.startsWith('{')) {
|
|
92
|
+
try {
|
|
93
|
+
const result = JSON.parse(lastLine);
|
|
94
|
+
if (typeof result === 'object' && 'success' in result) {
|
|
95
|
+
resolve(result);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Not valid JSON, continue to wrap
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Script didn't output valid JSON result, wrap output
|
|
104
|
+
if (code === 0) {
|
|
105
|
+
resolve({
|
|
106
|
+
success: true,
|
|
107
|
+
message: trimmedStdout || 'Script completed successfully',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
resolve({
|
|
112
|
+
success: false,
|
|
113
|
+
error: stderr.trim() || trimmedStdout || `Script exited with code ${code}`,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Convert a name to environment variable format
|
|
121
|
+
* Example: "feature-name" -> "FEATURE_NAME"
|
|
122
|
+
*/
|
|
123
|
+
function toEnvName(name) {
|
|
124
|
+
return name.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=shell-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-executor.js","sourceRoot":"","sources":["../../src/executor/shell-executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,UAAkB,EAClB,OAAsB;IAEtB,uBAAuB;IACvB,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;QACpC,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,qBAAqB,UAAU,EAAE;SACzC,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,2CAA2C;QAC3C,MAAM,GAAG,GAA2B,EAAE,GAAG,OAAO,CAAC,GAAG,EAA4B,CAAC;QAEjF,wCAAwC;QACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBAC1C,GAAG,CAAC,iBAAiB,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,sCAAsC;QACtC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3D,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CA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,GAAG,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript Executor
|
|
3
|
+
*
|
|
4
|
+
* Executes .ts files using tsx (preferred) or ts-node.
|
|
5
|
+
*/
|
|
6
|
+
import type { ScriptContext, ScriptResult } from './script-executor.js';
|
|
7
|
+
/**
|
|
8
|
+
* Execute a TypeScript file
|
|
9
|
+
*
|
|
10
|
+
* Strategy:
|
|
11
|
+
* 1. Try to use tsx (fast, modern TS executor)
|
|
12
|
+
* 2. Fall back to ts-node
|
|
13
|
+
* 3. Return error with installation instructions if neither available
|
|
14
|
+
*
|
|
15
|
+
* The script must export a default async function that accepts ScriptContext
|
|
16
|
+
* and returns a CommandResult.
|
|
17
|
+
*
|
|
18
|
+
* @param scriptPath - Absolute path to the TypeScript file
|
|
19
|
+
* @param context - Execution context
|
|
20
|
+
* @returns Script execution result
|
|
21
|
+
*/
|
|
22
|
+
export declare function executeTypeScript(scriptPath: string, context: ScriptContext): Promise<ScriptResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Helper to get context in TypeScript scripts
|
|
25
|
+
*
|
|
26
|
+
* Usage in script:
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { getScriptContext } from 'cli-agent';
|
|
29
|
+
* const context = getScriptContext();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function getScriptContext(): ScriptContext | null;
|
|
33
|
+
//# sourceMappingURL=ts-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-executor.d.ts","sourceRoot":"","sources":["../../src/executor/ts-executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGxE;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CA6BvB;AA2ED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,GAAG,IAAI,CAWvD"}
|