@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
|
@@ -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":"AA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
+
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"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript Executor
|
|
3
|
+
*
|
|
4
|
+
* Executes .ts files using tsx (preferred) or ts-node.
|
|
5
|
+
*/
|
|
6
|
+
import { spawn } from 'node:child_process';
|
|
7
|
+
import { pathExists } from '../services/file-system.service.js';
|
|
8
|
+
/**
|
|
9
|
+
* Execute a TypeScript file
|
|
10
|
+
*
|
|
11
|
+
* Strategy:
|
|
12
|
+
* 1. Try to use tsx (fast, modern TS executor)
|
|
13
|
+
* 2. Fall back to ts-node
|
|
14
|
+
* 3. Return error with installation instructions if neither available
|
|
15
|
+
*
|
|
16
|
+
* The script must export a default async function that accepts ScriptContext
|
|
17
|
+
* and returns a CommandResult.
|
|
18
|
+
*
|
|
19
|
+
* @param scriptPath - Absolute path to the TypeScript file
|
|
20
|
+
* @param context - Execution context
|
|
21
|
+
* @returns Script execution result
|
|
22
|
+
*/
|
|
23
|
+
export async function executeTypeScript(scriptPath, context) {
|
|
24
|
+
// Check if file exists
|
|
25
|
+
if (!(await pathExists(scriptPath))) {
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
error: `Script not found: ${scriptPath}`,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// Serialize context to pass to the script via environment variable
|
|
32
|
+
const contextJson = JSON.stringify(context);
|
|
33
|
+
// Try tsx first, then ts-node
|
|
34
|
+
const executors = ['tsx', 'ts-node'];
|
|
35
|
+
for (const executor of executors) {
|
|
36
|
+
const result = await runWithExecutor(executor, scriptPath, contextJson);
|
|
37
|
+
if (result !== null) {
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
error: 'No TypeScript executor found. Please install one:\n' +
|
|
44
|
+
' npm install -g tsx (recommended, faster)\n' +
|
|
45
|
+
' npm install -g ts-node',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Run script with a specific TypeScript executor
|
|
50
|
+
* Returns null if executor is not available
|
|
51
|
+
*/
|
|
52
|
+
async function runWithExecutor(executor, scriptPath, contextJson) {
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
const child = spawn(executor, [scriptPath], {
|
|
55
|
+
env: {
|
|
56
|
+
...process.env,
|
|
57
|
+
CLI_AGENT_CONTEXT: contextJson,
|
|
58
|
+
},
|
|
59
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
60
|
+
shell: false,
|
|
61
|
+
});
|
|
62
|
+
let stdout = '';
|
|
63
|
+
let stderr = '';
|
|
64
|
+
child.stdout?.on('data', (data) => {
|
|
65
|
+
stdout += data.toString();
|
|
66
|
+
});
|
|
67
|
+
child.stderr?.on('data', (data) => {
|
|
68
|
+
stderr += data.toString();
|
|
69
|
+
});
|
|
70
|
+
child.on('error', (error) => {
|
|
71
|
+
// Executor not found - return null to try next one
|
|
72
|
+
if (error.code === 'ENOENT') {
|
|
73
|
+
resolve(null);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
resolve({
|
|
77
|
+
success: false,
|
|
78
|
+
error: `Failed to execute with ${executor}: ${error.message}`,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
child.on('close', (code) => {
|
|
83
|
+
// Try to parse JSON output from script
|
|
84
|
+
const trimmedStdout = stdout.trim();
|
|
85
|
+
if (trimmedStdout) {
|
|
86
|
+
try {
|
|
87
|
+
const result = JSON.parse(trimmedStdout);
|
|
88
|
+
if (typeof result === 'object' && 'success' in result) {
|
|
89
|
+
resolve(result);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// Not JSON output, continue to wrap
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Script didn't output valid JSON result, wrap output
|
|
98
|
+
if (code === 0) {
|
|
99
|
+
resolve({
|
|
100
|
+
success: true,
|
|
101
|
+
message: trimmedStdout || 'Script completed successfully',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
resolve({
|
|
106
|
+
success: false,
|
|
107
|
+
error: stderr.trim() || trimmedStdout || `Script exited with code ${code}`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Helper to get context in TypeScript scripts
|
|
115
|
+
*
|
|
116
|
+
* Usage in script:
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import { getScriptContext } from 'cli-agent';
|
|
119
|
+
* const context = getScriptContext();
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export function getScriptContext() {
|
|
123
|
+
const contextJson = process.env.CLI_AGENT_CONTEXT;
|
|
124
|
+
if (!contextJson) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
return JSON.parse(contextJson);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=ts-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-executor.js","sourceRoot":"","sources":["../../src/executor/ts-executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAEhE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,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,mEAAmE;IACnE,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAE5C,8BAA8B;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CAAC,iBAAiB,CAAC;IAClD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAkB,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library Entry Point
|
|
3
|
+
*
|
|
4
|
+
* MCP server that turns your scripts into AI-powered tools.
|
|
5
|
+
* Exports the public API for consumers to use in their scripts.
|
|
6
|
+
*/
|
|
7
|
+
export type { OutputFormat, LogLevel, CommandResult, ScriptContext, ExitCodeValue, } from "./types/index.js";
|
|
8
|
+
export { ExitCode } from "./types/index.js";
|
|
9
|
+
export type { CliConfig, CommandConfig, ArgumentConfig, OptionConfig, LoadConfigResult, } from "./config/config-schema.js";
|
|
10
|
+
export { toKebabCase, toPascalCase, toCamelCase, toScreamingSnakeCase, isValidFeatureName, getFeatureNameError, } from "./services/naming.service.js";
|
|
11
|
+
export { pathExists, isDirectory, createDirectory, createFile, resolvePath, joinPath, createEntries, checkExistingPaths, } from "./services/file-system.service.js";
|
|
12
|
+
export { setLogLevel, getLogLevel, logError, logWarn, logInfo, logSuccess, logDebug, logTrace, logBox, resetLogger, } from "./infra/logger.js";
|
|
13
|
+
export { outputResult } from "./infra/output.js";
|
|
14
|
+
export { getScriptContext } from "./executor/ts-executor.js";
|
|
15
|
+
export { createMcpServer, startMcpServer } from "./mcp/mcp-server.js";
|
|
16
|
+
export type { McpServerOptions } from "./mcp/mcp-server.js";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EACV,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,aAAa,EACb,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,YAAY,EACV,SAAS,EACT,aAAa,EACb,cAAc,EACd,YAAY,EACZ,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,UAAU,EACV,WAAW,EACX,eAAe,EACf,UAAU,EACV,WAAW,EACX,QAAQ,EACR,aAAa,EACb,kBAAkB,GACnB,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EACR,OAAO,EACP,OAAO,EACP,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACtE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library Entry Point
|
|
3
|
+
*
|
|
4
|
+
* MCP server that turns your scripts into AI-powered tools.
|
|
5
|
+
* Exports the public API for consumers to use in their scripts.
|
|
6
|
+
*/
|
|
7
|
+
export { ExitCode } from "./types/index.js";
|
|
8
|
+
// Utility Services (consumers can use these in their scripts)
|
|
9
|
+
export { toKebabCase, toPascalCase, toCamelCase, toScreamingSnakeCase, isValidFeatureName, getFeatureNameError, } from "./services/naming.service.js";
|
|
10
|
+
export { pathExists, isDirectory, createDirectory, createFile, resolvePath, joinPath, createEntries, checkExistingPaths, } from "./services/file-system.service.js";
|
|
11
|
+
// Infrastructure (consumers can use these in their scripts)
|
|
12
|
+
export { setLogLevel, getLogLevel, logError, logWarn, logInfo, logSuccess, logDebug, logTrace, logBox, resetLogger, } from "./infra/logger.js";
|
|
13
|
+
export { outputResult } from "./infra/output.js";
|
|
14
|
+
// Script context helper (for TypeScript scripts executed via tsx/ts-node)
|
|
15
|
+
export { getScriptContext } from "./executor/ts-executor.js";
|
|
16
|
+
// MCP Server (for programmatic usage)
|
|
17
|
+
export { createMcpServer, startMcpServer } from "./mcp/mcp-server.js";
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAW5C,8DAA8D;AAC9D,OAAO,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,UAAU,EACV,WAAW,EACX,eAAe,EACf,UAAU,EACV,WAAW,EACX,QAAQ,EACR,aAAa,EACb,kBAAkB,GACnB,MAAM,mCAAmC,CAAC;AAE3C,4DAA4D;AAC5D,OAAO,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EACR,OAAO,EACP,OAAO,EACP,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,0EAA0E;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,sCAAsC;AACtC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { LogLevel } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Set the log level for the logger
|
|
4
|
+
*/
|
|
5
|
+
export declare function setLogLevel(level: LogLevel): void;
|
|
6
|
+
/**
|
|
7
|
+
* Get the current log level
|
|
8
|
+
*/
|
|
9
|
+
export declare function getLogLevel(): LogLevel;
|
|
10
|
+
/**
|
|
11
|
+
* Log an error message (always shown unless quiet)
|
|
12
|
+
*/
|
|
13
|
+
export declare function logError(message: string, ...args: unknown[]): void;
|
|
14
|
+
/**
|
|
15
|
+
* Log a warning message
|
|
16
|
+
*/
|
|
17
|
+
export declare function logWarn(message: string, ...args: unknown[]): void;
|
|
18
|
+
/**
|
|
19
|
+
* Log an info message
|
|
20
|
+
*/
|
|
21
|
+
export declare function logInfo(message: string, ...args: unknown[]): void;
|
|
22
|
+
/**
|
|
23
|
+
* Log a success message
|
|
24
|
+
*/
|
|
25
|
+
export declare function logSuccess(message: string, ...args: unknown[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* Log a debug message (only in verbose/debug mode)
|
|
28
|
+
*/
|
|
29
|
+
export declare function logDebug(message: string, ...args: unknown[]): void;
|
|
30
|
+
/**
|
|
31
|
+
* Log a trace message (only in debug mode)
|
|
32
|
+
*/
|
|
33
|
+
export declare function logTrace(message: string, ...args: unknown[]): void;
|
|
34
|
+
/**
|
|
35
|
+
* Create a boxed message for important outputs
|
|
36
|
+
*/
|
|
37
|
+
export declare function logBox(message: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Reset logger instance (useful for testing)
|
|
40
|
+
*/
|
|
41
|
+
export declare function resetLogger(): void;
|
|
42
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/infra/logger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAoClD;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAKjD;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,QAAQ,CAEtC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAElE;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAEjE;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAEjE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAEpE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAElE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAElE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE5C;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAGlC"}
|