@elizaos/plugin-cli 2.0.0-alpha.3
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/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +169 -0
- package/dist/registry.d.ts +43 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +77 -0
- package/dist/types.d.ts +127 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/utils.d.ts +66 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +281 -0
- package/package.json +69 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @elizaos/plugin-cli
|
|
3
|
+
*
|
|
4
|
+
* CLI framework plugin for ElizaOS agents
|
|
5
|
+
*
|
|
6
|
+
* Provides:
|
|
7
|
+
* - CLI command registration and management
|
|
8
|
+
* - Progress reporting utilities
|
|
9
|
+
* - Duration/timeout parsing
|
|
10
|
+
* - Common CLI dependencies
|
|
11
|
+
*/
|
|
12
|
+
import type { IAgentRuntime, Plugin } from "@elizaos/core";
|
|
13
|
+
import { Command } from "commander";
|
|
14
|
+
export { addSubcommand, clearCliCommands, defineCliCommand, getCliCommand, listCliCommands, registerAllCommands, registerCliCommand, unregisterCliCommand, } from "./registry.js";
|
|
15
|
+
export * from "./types.js";
|
|
16
|
+
export { createDefaultDeps, createProgressReporter, DEFAULT_CLI_NAME, DEFAULT_CLI_VERSION, formatBytes, formatCliCommand, formatDuration, isInteractive, parseDurationMs, parseTimeoutMs, resolveCliName, withProgress, } from "./utils.js";
|
|
17
|
+
/**
|
|
18
|
+
* Build the Commander program with all registered commands
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildProgram(options?: {
|
|
21
|
+
name?: string;
|
|
22
|
+
version?: string;
|
|
23
|
+
getRuntime?: () => IAgentRuntime | null;
|
|
24
|
+
}): Command;
|
|
25
|
+
/**
|
|
26
|
+
* Run the CLI with the given arguments
|
|
27
|
+
*/
|
|
28
|
+
export declare function runCli(argv?: string[], options?: {
|
|
29
|
+
name?: string;
|
|
30
|
+
version?: string;
|
|
31
|
+
getRuntime?: () => IAgentRuntime | null;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* CLI Plugin for ElizaOS
|
|
35
|
+
*
|
|
36
|
+
* Provides CLI command infrastructure for the agent runtime.
|
|
37
|
+
*
|
|
38
|
+
* Configuration:
|
|
39
|
+
* - CLI_NAME: CLI command name (default: "elizaos")
|
|
40
|
+
* - CLI_VERSION: CLI version string
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { cliPlugin, buildProgram, registerCliCommand, defineCliCommand } from '@elizaos/plugin-cli';
|
|
45
|
+
*
|
|
46
|
+
* // Register a custom command
|
|
47
|
+
* registerCliCommand(defineCliCommand(
|
|
48
|
+
* 'mycommand',
|
|
49
|
+
* 'My custom command',
|
|
50
|
+
* (ctx) => {
|
|
51
|
+
* ctx.program.command('mycommand')
|
|
52
|
+
* .description('My custom command')
|
|
53
|
+
* .action(() => console.log('Hello!'));
|
|
54
|
+
* }
|
|
55
|
+
* ));
|
|
56
|
+
*
|
|
57
|
+
* // Build and run
|
|
58
|
+
* const program = buildProgram();
|
|
59
|
+
* await program.parseAsync(process.argv);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const cliPlugin: Plugin;
|
|
63
|
+
export default cliPlugin;
|
|
64
|
+
export { Command } from "commander";
|
|
65
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAEvB,cAAc,YAAY,CAAC;AAG3B,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,YAAY,GACb,MAAM,YAAY,CAAC;AAUpB;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,aAAa,GAAG,IAAI,CAAC;CACzC,GAAG,OAAO,CAoBV;AAED;;GAEG;AACH,wBAAsB,MAAM,CAC1B,IAAI,CAAC,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE;IACR,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,aAAa,GAAG,IAAI,CAAC;CACzC,GACA,OAAO,CAAC,IAAI,CAAC,CAcf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,SAAS,EAAE,MAiCvB,CAAC;AAEF,eAAe,SAAS,CAAC;AAGzB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @elizaos/plugin-cli
|
|
3
|
+
*
|
|
4
|
+
* CLI framework plugin for ElizaOS agents
|
|
5
|
+
*
|
|
6
|
+
* Provides:
|
|
7
|
+
* - CLI command registration and management
|
|
8
|
+
* - Progress reporting utilities
|
|
9
|
+
* - Duration/timeout parsing
|
|
10
|
+
* - Common CLI dependencies
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { logger } from "@elizaos/core";
|
|
49
|
+
import { Command } from "commander";
|
|
50
|
+
// Registry
|
|
51
|
+
export { addSubcommand, clearCliCommands, defineCliCommand, getCliCommand, listCliCommands, registerAllCommands, registerCliCommand, unregisterCliCommand, } from "./registry.js";
|
|
52
|
+
// Types
|
|
53
|
+
export * from "./types.js";
|
|
54
|
+
// Utils
|
|
55
|
+
export { createDefaultDeps, createProgressReporter, DEFAULT_CLI_NAME, DEFAULT_CLI_VERSION, formatBytes, formatCliCommand, formatDuration, isInteractive, parseDurationMs, parseTimeoutMs, resolveCliName, withProgress, } from "./utils.js";
|
|
56
|
+
import { listCliCommands, registerAllCommands } from "./registry.js";
|
|
57
|
+
import { DEFAULT_CLI_NAME, DEFAULT_CLI_VERSION, resolveCliName, } from "./utils.js";
|
|
58
|
+
/**
|
|
59
|
+
* Build the Commander program with all registered commands
|
|
60
|
+
*/
|
|
61
|
+
export function buildProgram(options) {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
var cliName = (_a = options === null || options === void 0 ? void 0 : options.name) !== null && _a !== void 0 ? _a : resolveCliName();
|
|
64
|
+
var version = (_b = options === null || options === void 0 ? void 0 : options.version) !== null && _b !== void 0 ? _b : DEFAULT_CLI_VERSION;
|
|
65
|
+
var program = new Command()
|
|
66
|
+
.name(cliName)
|
|
67
|
+
.version(version)
|
|
68
|
+
.description("".concat(cliName, " - ElizaOS agent CLI"));
|
|
69
|
+
var ctx = {
|
|
70
|
+
program: program,
|
|
71
|
+
getRuntime: options === null || options === void 0 ? void 0 : options.getRuntime,
|
|
72
|
+
cliName: cliName,
|
|
73
|
+
version: version,
|
|
74
|
+
};
|
|
75
|
+
// Register all commands
|
|
76
|
+
registerAllCommands(ctx);
|
|
77
|
+
return program;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Run the CLI with the given arguments
|
|
81
|
+
*/
|
|
82
|
+
export function runCli(argv, options) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
var program, error_1;
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
switch (_a.label) {
|
|
87
|
+
case 0:
|
|
88
|
+
program = buildProgram(options);
|
|
89
|
+
_a.label = 1;
|
|
90
|
+
case 1:
|
|
91
|
+
_a.trys.push([1, 3, , 4]);
|
|
92
|
+
return [4 /*yield*/, program.parseAsync(argv !== null && argv !== void 0 ? argv : process.argv)];
|
|
93
|
+
case 2:
|
|
94
|
+
_a.sent();
|
|
95
|
+
return [3 /*break*/, 4];
|
|
96
|
+
case 3:
|
|
97
|
+
error_1 = _a.sent();
|
|
98
|
+
if (error_1 instanceof Error) {
|
|
99
|
+
// Commander throws an error for --help and --version
|
|
100
|
+
if (error_1.message.includes("outputHelp")) {
|
|
101
|
+
return [2 /*return*/];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
throw error_1;
|
|
105
|
+
case 4: return [2 /*return*/];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* CLI Plugin for ElizaOS
|
|
112
|
+
*
|
|
113
|
+
* Provides CLI command infrastructure for the agent runtime.
|
|
114
|
+
*
|
|
115
|
+
* Configuration:
|
|
116
|
+
* - CLI_NAME: CLI command name (default: "elizaos")
|
|
117
|
+
* - CLI_VERSION: CLI version string
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { cliPlugin, buildProgram, registerCliCommand, defineCliCommand } from '@elizaos/plugin-cli';
|
|
122
|
+
*
|
|
123
|
+
* // Register a custom command
|
|
124
|
+
* registerCliCommand(defineCliCommand(
|
|
125
|
+
* 'mycommand',
|
|
126
|
+
* 'My custom command',
|
|
127
|
+
* (ctx) => {
|
|
128
|
+
* ctx.program.command('mycommand')
|
|
129
|
+
* .description('My custom command')
|
|
130
|
+
* .action(() => console.log('Hello!'));
|
|
131
|
+
* }
|
|
132
|
+
* ));
|
|
133
|
+
*
|
|
134
|
+
* // Build and run
|
|
135
|
+
* const program = buildProgram();
|
|
136
|
+
* await program.parseAsync(process.argv);
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export var cliPlugin = {
|
|
140
|
+
name: "cli",
|
|
141
|
+
description: "CLI framework plugin for command registration and execution",
|
|
142
|
+
providers: [],
|
|
143
|
+
actions: [],
|
|
144
|
+
services: [],
|
|
145
|
+
routes: [],
|
|
146
|
+
config: {
|
|
147
|
+
CLI_NAME: DEFAULT_CLI_NAME,
|
|
148
|
+
CLI_VERSION: DEFAULT_CLI_VERSION,
|
|
149
|
+
},
|
|
150
|
+
init: function (_config, _runtime) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
+
var commands;
|
|
153
|
+
return __generator(this, function (_a) {
|
|
154
|
+
try {
|
|
155
|
+
commands = listCliCommands();
|
|
156
|
+
logger.info({ commandCount: commands.length }, "[CLIPlugin] Plugin initialized");
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
logger.error("[CLIPlugin] Error initializing:", error instanceof Error ? error.message : String(error));
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
return [2 /*return*/];
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
export default cliPlugin;
|
|
168
|
+
// Re-export Command for convenience
|
|
169
|
+
export { Command } from "commander";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI command registry
|
|
3
|
+
*
|
|
4
|
+
* Provides command registration and management for the CLI plugin.
|
|
5
|
+
*/
|
|
6
|
+
import type { Command } from "commander";
|
|
7
|
+
import type { CliCommand, CliContext, CliRegistrationFn } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Register a CLI command
|
|
10
|
+
*/
|
|
11
|
+
export declare function registerCliCommand(command: CliCommand): void;
|
|
12
|
+
/**
|
|
13
|
+
* Unregister a CLI command
|
|
14
|
+
*/
|
|
15
|
+
export declare function unregisterCliCommand(name: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Get a CLI command by name
|
|
18
|
+
*/
|
|
19
|
+
export declare function getCliCommand(name: string): CliCommand | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* List all registered CLI commands
|
|
22
|
+
*/
|
|
23
|
+
export declare function listCliCommands(): CliCommand[];
|
|
24
|
+
/**
|
|
25
|
+
* Register all commands with the program
|
|
26
|
+
*/
|
|
27
|
+
export declare function registerAllCommands(ctx: CliContext): void;
|
|
28
|
+
/**
|
|
29
|
+
* Clear all registered commands (for testing)
|
|
30
|
+
*/
|
|
31
|
+
export declare function clearCliCommands(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Helper to create a CLI command definition
|
|
34
|
+
*/
|
|
35
|
+
export declare function defineCliCommand(name: string, description: string, register: CliRegistrationFn, options?: {
|
|
36
|
+
aliases?: string[];
|
|
37
|
+
priority?: number;
|
|
38
|
+
}): CliCommand;
|
|
39
|
+
/**
|
|
40
|
+
* Helper to create a subcommand on an existing command
|
|
41
|
+
*/
|
|
42
|
+
export declare function addSubcommand(parent: Command, name: string, description: string): Command;
|
|
43
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAO5E;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAO5D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAElE;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,UAAU,EAAE,CAI9C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI,CAazD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACA,UAAU,CAQZ;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,OAAO,CAET"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI command registry
|
|
3
|
+
*
|
|
4
|
+
* Provides command registration and management for the CLI plugin.
|
|
5
|
+
*/
|
|
6
|
+
import { logger } from "@elizaos/core";
|
|
7
|
+
/**
|
|
8
|
+
* Internal registry of CLI commands
|
|
9
|
+
*/
|
|
10
|
+
var commands = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* Register a CLI command
|
|
13
|
+
*/
|
|
14
|
+
export function registerCliCommand(command) {
|
|
15
|
+
if (commands.has(command.name)) {
|
|
16
|
+
logger.warn("[CLI] Command \"".concat(command.name, "\" already registered, replacing"));
|
|
17
|
+
}
|
|
18
|
+
commands.set(command.name, command);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Unregister a CLI command
|
|
22
|
+
*/
|
|
23
|
+
export function unregisterCliCommand(name) {
|
|
24
|
+
return commands.delete(name);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get a CLI command by name
|
|
28
|
+
*/
|
|
29
|
+
export function getCliCommand(name) {
|
|
30
|
+
return commands.get(name);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* List all registered CLI commands
|
|
34
|
+
*/
|
|
35
|
+
export function listCliCommands() {
|
|
36
|
+
return Array.from(commands.values()).sort(function (a, b) { var _a, _b; return ((_a = a.priority) !== null && _a !== void 0 ? _a : 100) - ((_b = b.priority) !== null && _b !== void 0 ? _b : 100); });
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Register all commands with the program
|
|
40
|
+
*/
|
|
41
|
+
export function registerAllCommands(ctx) {
|
|
42
|
+
var sorted = listCliCommands();
|
|
43
|
+
for (var _i = 0, sorted_1 = sorted; _i < sorted_1.length; _i++) {
|
|
44
|
+
var command = sorted_1[_i];
|
|
45
|
+
try {
|
|
46
|
+
command.register(ctx);
|
|
47
|
+
logger.debug("[CLI] Registered command: ".concat(command.name));
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
logger.error("[CLI] Failed to register command \"".concat(command.name, "\":"), error instanceof Error ? error.message : String(error));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Clear all registered commands (for testing)
|
|
56
|
+
*/
|
|
57
|
+
export function clearCliCommands() {
|
|
58
|
+
commands.clear();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Helper to create a CLI command definition
|
|
62
|
+
*/
|
|
63
|
+
export function defineCliCommand(name, description, register, options) {
|
|
64
|
+
return {
|
|
65
|
+
name: name,
|
|
66
|
+
description: description,
|
|
67
|
+
register: register,
|
|
68
|
+
aliases: options === null || options === void 0 ? void 0 : options.aliases,
|
|
69
|
+
priority: options === null || options === void 0 ? void 0 : options.priority,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Helper to create a subcommand on an existing command
|
|
74
|
+
*/
|
|
75
|
+
export function addSubcommand(parent, name, description) {
|
|
76
|
+
return parent.command(name).description(description);
|
|
77
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI plugin types
|
|
3
|
+
*
|
|
4
|
+
* Core types for CLI command registration and execution.
|
|
5
|
+
*/
|
|
6
|
+
import type { IAgentRuntime } from "@elizaos/core";
|
|
7
|
+
import type { Command } from "commander";
|
|
8
|
+
/**
|
|
9
|
+
* Logger interface for CLI context
|
|
10
|
+
*/
|
|
11
|
+
export interface CliLogger {
|
|
12
|
+
info: (msg: string) => void;
|
|
13
|
+
warn: (msg: string) => void;
|
|
14
|
+
error: (msg: string) => void;
|
|
15
|
+
debug?: (msg: string) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* CLI context provided to command handlers
|
|
19
|
+
*/
|
|
20
|
+
export interface CliContext {
|
|
21
|
+
/** Commander program instance */
|
|
22
|
+
program: Command;
|
|
23
|
+
/** Optional runtime getter for plugins that need it */
|
|
24
|
+
getRuntime?: () => IAgentRuntime | null;
|
|
25
|
+
/** CLI name (e.g., "elizaos", "otto") */
|
|
26
|
+
cliName: string;
|
|
27
|
+
/** CLI version */
|
|
28
|
+
version: string;
|
|
29
|
+
/** Optional configuration object */
|
|
30
|
+
config?: Record<string, unknown>;
|
|
31
|
+
/** Optional workspace directory */
|
|
32
|
+
workspaceDir?: string;
|
|
33
|
+
/** Optional logger for CLI output */
|
|
34
|
+
logger?: CliLogger;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* CLI command registration function signature
|
|
38
|
+
*/
|
|
39
|
+
export type CliRegistrationFn = (ctx: CliContext) => void;
|
|
40
|
+
/**
|
|
41
|
+
* CLI command definition
|
|
42
|
+
*/
|
|
43
|
+
export interface CliCommand {
|
|
44
|
+
/** Command name (e.g., "run", "config") */
|
|
45
|
+
name: string;
|
|
46
|
+
/** Command description */
|
|
47
|
+
description: string;
|
|
48
|
+
/** Command aliases */
|
|
49
|
+
aliases?: string[];
|
|
50
|
+
/** Registration function */
|
|
51
|
+
register: CliRegistrationFn;
|
|
52
|
+
/** Priority for registration order (lower = earlier) */
|
|
53
|
+
priority?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* CLI plugin configuration
|
|
57
|
+
*/
|
|
58
|
+
export interface CliPluginConfig {
|
|
59
|
+
/** CLI name */
|
|
60
|
+
name?: string;
|
|
61
|
+
/** CLI version */
|
|
62
|
+
version?: string;
|
|
63
|
+
/** Commands to register */
|
|
64
|
+
commands?: CliCommand[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Progress reporter interface
|
|
68
|
+
*/
|
|
69
|
+
export interface ProgressReporter {
|
|
70
|
+
/** Start progress reporting */
|
|
71
|
+
start(message: string): void;
|
|
72
|
+
/** Update progress message */
|
|
73
|
+
update(message: string): void;
|
|
74
|
+
/** Complete with success */
|
|
75
|
+
success(message: string): void;
|
|
76
|
+
/** Complete with failure */
|
|
77
|
+
fail(message: string): void;
|
|
78
|
+
/** Stop progress reporting */
|
|
79
|
+
stop(): void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Progress options
|
|
83
|
+
*/
|
|
84
|
+
export interface ProgressOptions {
|
|
85
|
+
/** Initial message */
|
|
86
|
+
message?: string;
|
|
87
|
+
/** Whether to show spinner */
|
|
88
|
+
spinner?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* CLI dependencies for command execution
|
|
92
|
+
*/
|
|
93
|
+
export interface CliDeps {
|
|
94
|
+
/** Log function */
|
|
95
|
+
log: (message: string) => void;
|
|
96
|
+
/** Error function */
|
|
97
|
+
error: (message: string) => void;
|
|
98
|
+
/** Exit function */
|
|
99
|
+
exit: (code: number) => void;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Duration parsing result
|
|
103
|
+
*/
|
|
104
|
+
export interface ParsedDuration {
|
|
105
|
+
/** Duration in milliseconds */
|
|
106
|
+
ms: number;
|
|
107
|
+
/** Original string */
|
|
108
|
+
original: string;
|
|
109
|
+
/** Whether parsing was successful */
|
|
110
|
+
valid: boolean;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Command options commonly used across CLI commands
|
|
114
|
+
*/
|
|
115
|
+
export interface CommonCommandOptions {
|
|
116
|
+
/** JSON output format */
|
|
117
|
+
json?: boolean;
|
|
118
|
+
/** Verbose output */
|
|
119
|
+
verbose?: boolean;
|
|
120
|
+
/** Quiet mode (minimal output) */
|
|
121
|
+
quiet?: boolean;
|
|
122
|
+
/** Force action without confirmation */
|
|
123
|
+
force?: boolean;
|
|
124
|
+
/** Dry run (show what would happen) */
|
|
125
|
+
dryRun?: boolean;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
|
package/dist/types.js
ADDED
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI utilities
|
|
3
|
+
*
|
|
4
|
+
* Common utilities for CLI operations.
|
|
5
|
+
*/
|
|
6
|
+
import type { CliDeps, ParsedDuration, ProgressOptions, ProgressReporter } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Default CLI name
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_CLI_NAME = "elizaos";
|
|
11
|
+
/**
|
|
12
|
+
* Default CLI version
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_CLI_VERSION = "1.0.0";
|
|
15
|
+
/**
|
|
16
|
+
* Create default CLI dependencies
|
|
17
|
+
*/
|
|
18
|
+
export declare function createDefaultDeps(): CliDeps;
|
|
19
|
+
/**
|
|
20
|
+
* Create a progress reporter
|
|
21
|
+
*/
|
|
22
|
+
export declare function createProgressReporter(deps: CliDeps, options?: ProgressOptions): ProgressReporter;
|
|
23
|
+
/**
|
|
24
|
+
* Execute with progress reporting
|
|
25
|
+
*/
|
|
26
|
+
export declare function withProgress<T>(deps: CliDeps, message: string, fn: () => Promise<T>): Promise<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Parse a duration string to milliseconds
|
|
29
|
+
*
|
|
30
|
+
* Supports formats like:
|
|
31
|
+
* - "1s", "30s" (seconds)
|
|
32
|
+
* - "1m", "5m" (minutes)
|
|
33
|
+
* - "1h", "2h" (hours)
|
|
34
|
+
* - "1d", "7d" (days)
|
|
35
|
+
* - "1000" (milliseconds)
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseDurationMs(input: string): ParsedDuration;
|
|
38
|
+
/**
|
|
39
|
+
* Parse a timeout string with defaults
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseTimeoutMs(input: string | undefined, defaultMs: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Format a CLI command with profile/env context
|
|
44
|
+
*/
|
|
45
|
+
export declare function formatCliCommand(command: string, options?: {
|
|
46
|
+
cliName?: string;
|
|
47
|
+
profile?: string;
|
|
48
|
+
env?: string;
|
|
49
|
+
}): string;
|
|
50
|
+
/**
|
|
51
|
+
* Resolve CLI name from argv
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveCliName(argv?: string[]): string;
|
|
54
|
+
/**
|
|
55
|
+
* Check if running interactively
|
|
56
|
+
*/
|
|
57
|
+
export declare function isInteractive(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Format bytes to human readable string
|
|
60
|
+
*/
|
|
61
|
+
export declare function formatBytes(bytes: number): string;
|
|
62
|
+
/**
|
|
63
|
+
* Format duration to human readable string
|
|
64
|
+
*/
|
|
65
|
+
export declare function formatDuration(ms: number): string;
|
|
66
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,eAAe,EACf,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAM3C;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,OAAO,EACb,OAAO,CAAC,EAAE,eAAe,GACxB,gBAAgB,CA+DlB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAClC,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,EACf,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAWZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAuD7D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,SAAS,EAAE,MAAM,GAChB,MAAM,CAIR;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,GACA,MAAM,CAcR;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAStD;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWjD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAKjD"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI utilities
|
|
3
|
+
*
|
|
4
|
+
* Common utilities for CLI operations.
|
|
5
|
+
*/
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
16
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
17
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
18
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
19
|
+
function step(op) {
|
|
20
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
21
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
22
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
23
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
24
|
+
switch (op[0]) {
|
|
25
|
+
case 0: case 1: t = op; break;
|
|
26
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
27
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
28
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
29
|
+
default:
|
|
30
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
31
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
32
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
33
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
34
|
+
if (t[2]) _.ops.pop();
|
|
35
|
+
_.trys.pop(); continue;
|
|
36
|
+
}
|
|
37
|
+
op = body.call(thisArg, _);
|
|
38
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
39
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Default CLI name
|
|
44
|
+
*/
|
|
45
|
+
export var DEFAULT_CLI_NAME = "elizaos";
|
|
46
|
+
/**
|
|
47
|
+
* Default CLI version
|
|
48
|
+
*/
|
|
49
|
+
export var DEFAULT_CLI_VERSION = "1.0.0";
|
|
50
|
+
/**
|
|
51
|
+
* Create default CLI dependencies
|
|
52
|
+
*/
|
|
53
|
+
export function createDefaultDeps() {
|
|
54
|
+
return {
|
|
55
|
+
log: function (message) { return console.log(message); },
|
|
56
|
+
error: function (message) { return console.error(message); },
|
|
57
|
+
exit: function (code) { return process.exit(code); },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a progress reporter
|
|
62
|
+
*/
|
|
63
|
+
export function createProgressReporter(deps, options) {
|
|
64
|
+
var _a;
|
|
65
|
+
var running = false;
|
|
66
|
+
var intervalId = null;
|
|
67
|
+
var spinnerFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
68
|
+
var frameIndex = 0;
|
|
69
|
+
var currentMessage = (_a = options === null || options === void 0 ? void 0 : options.message) !== null && _a !== void 0 ? _a : "";
|
|
70
|
+
var clearLine = function () {
|
|
71
|
+
if (process.stdout.isTTY) {
|
|
72
|
+
process.stdout.write("\r\x1b[K");
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var writeSpinner = function () {
|
|
76
|
+
if (process.stdout.isTTY && (options === null || options === void 0 ? void 0 : options.spinner) !== false) {
|
|
77
|
+
clearLine();
|
|
78
|
+
process.stdout.write("".concat(spinnerFrames[frameIndex], " ").concat(currentMessage));
|
|
79
|
+
frameIndex = (frameIndex + 1) % spinnerFrames.length;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
start: function (message) {
|
|
84
|
+
currentMessage = message;
|
|
85
|
+
running = true;
|
|
86
|
+
if ((options === null || options === void 0 ? void 0 : options.spinner) !== false && process.stdout.isTTY) {
|
|
87
|
+
writeSpinner();
|
|
88
|
+
intervalId = setInterval(writeSpinner, 80);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
deps.log(message);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
update: function (message) {
|
|
95
|
+
currentMessage = message;
|
|
96
|
+
if (!running && !process.stdout.isTTY) {
|
|
97
|
+
deps.log(message);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
success: function (message) {
|
|
101
|
+
this.stop();
|
|
102
|
+
if (process.stdout.isTTY) {
|
|
103
|
+
clearLine();
|
|
104
|
+
}
|
|
105
|
+
deps.log("\u2713 ".concat(message));
|
|
106
|
+
},
|
|
107
|
+
fail: function (message) {
|
|
108
|
+
this.stop();
|
|
109
|
+
if (process.stdout.isTTY) {
|
|
110
|
+
clearLine();
|
|
111
|
+
}
|
|
112
|
+
deps.error("\u2717 ".concat(message));
|
|
113
|
+
},
|
|
114
|
+
stop: function () {
|
|
115
|
+
running = false;
|
|
116
|
+
if (intervalId) {
|
|
117
|
+
clearInterval(intervalId);
|
|
118
|
+
intervalId = null;
|
|
119
|
+
}
|
|
120
|
+
if (process.stdout.isTTY) {
|
|
121
|
+
clearLine();
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Execute with progress reporting
|
|
128
|
+
*/
|
|
129
|
+
export function withProgress(deps, message, fn) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
var progress, result, error_1;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
134
|
+
case 0:
|
|
135
|
+
progress = createProgressReporter(deps, { message: message, spinner: true });
|
|
136
|
+
progress.start(message);
|
|
137
|
+
_a.label = 1;
|
|
138
|
+
case 1:
|
|
139
|
+
_a.trys.push([1, 3, , 4]);
|
|
140
|
+
return [4 /*yield*/, fn()];
|
|
141
|
+
case 2:
|
|
142
|
+
result = _a.sent();
|
|
143
|
+
progress.success(message);
|
|
144
|
+
return [2 /*return*/, result];
|
|
145
|
+
case 3:
|
|
146
|
+
error_1 = _a.sent();
|
|
147
|
+
progress.fail(error_1 instanceof Error ? error_1.message : String(error_1));
|
|
148
|
+
throw error_1;
|
|
149
|
+
case 4: return [2 /*return*/];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Parse a duration string to milliseconds
|
|
156
|
+
*
|
|
157
|
+
* Supports formats like:
|
|
158
|
+
* - "1s", "30s" (seconds)
|
|
159
|
+
* - "1m", "5m" (minutes)
|
|
160
|
+
* - "1h", "2h" (hours)
|
|
161
|
+
* - "1d", "7d" (days)
|
|
162
|
+
* - "1000" (milliseconds)
|
|
163
|
+
*/
|
|
164
|
+
export function parseDurationMs(input) {
|
|
165
|
+
var _a;
|
|
166
|
+
var trimmed = input.trim().toLowerCase();
|
|
167
|
+
// Check for number only (milliseconds)
|
|
168
|
+
var numOnly = parseInt(trimmed, 10);
|
|
169
|
+
if (!Number.isNaN(numOnly) && String(numOnly) === trimmed) {
|
|
170
|
+
return { ms: numOnly, original: input, valid: true };
|
|
171
|
+
}
|
|
172
|
+
// Parse with unit
|
|
173
|
+
var match = trimmed.match(/^(\d+(?:\.\d+)?)\s*(s|sec|second|seconds|m|min|minute|minutes|h|hr|hour|hours|d|day|days|ms|millisecond|milliseconds)?$/);
|
|
174
|
+
if (!match) {
|
|
175
|
+
return { ms: 0, original: input, valid: false };
|
|
176
|
+
}
|
|
177
|
+
var value = parseFloat(match[1]);
|
|
178
|
+
var unit = (_a = match[2]) !== null && _a !== void 0 ? _a : "ms";
|
|
179
|
+
var multiplier;
|
|
180
|
+
switch (unit) {
|
|
181
|
+
case "ms":
|
|
182
|
+
case "millisecond":
|
|
183
|
+
case "milliseconds":
|
|
184
|
+
multiplier = 1;
|
|
185
|
+
break;
|
|
186
|
+
case "s":
|
|
187
|
+
case "sec":
|
|
188
|
+
case "second":
|
|
189
|
+
case "seconds":
|
|
190
|
+
multiplier = 1000;
|
|
191
|
+
break;
|
|
192
|
+
case "m":
|
|
193
|
+
case "min":
|
|
194
|
+
case "minute":
|
|
195
|
+
case "minutes":
|
|
196
|
+
multiplier = 60 * 1000;
|
|
197
|
+
break;
|
|
198
|
+
case "h":
|
|
199
|
+
case "hr":
|
|
200
|
+
case "hour":
|
|
201
|
+
case "hours":
|
|
202
|
+
multiplier = 60 * 60 * 1000;
|
|
203
|
+
break;
|
|
204
|
+
case "d":
|
|
205
|
+
case "day":
|
|
206
|
+
case "days":
|
|
207
|
+
multiplier = 24 * 60 * 60 * 1000;
|
|
208
|
+
break;
|
|
209
|
+
default:
|
|
210
|
+
return { ms: 0, original: input, valid: false };
|
|
211
|
+
}
|
|
212
|
+
return { ms: Math.round(value * multiplier), original: input, valid: true };
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Parse a timeout string with defaults
|
|
216
|
+
*/
|
|
217
|
+
export function parseTimeoutMs(input, defaultMs) {
|
|
218
|
+
if (!input)
|
|
219
|
+
return defaultMs;
|
|
220
|
+
var parsed = parseDurationMs(input);
|
|
221
|
+
return parsed.valid ? parsed.ms : defaultMs;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Format a CLI command with profile/env context
|
|
225
|
+
*/
|
|
226
|
+
export function formatCliCommand(command, options) {
|
|
227
|
+
var _a;
|
|
228
|
+
var parts = [(_a = options === null || options === void 0 ? void 0 : options.cliName) !== null && _a !== void 0 ? _a : DEFAULT_CLI_NAME];
|
|
229
|
+
if (options === null || options === void 0 ? void 0 : options.profile) {
|
|
230
|
+
parts.push("--profile ".concat(options.profile));
|
|
231
|
+
}
|
|
232
|
+
if (options === null || options === void 0 ? void 0 : options.env) {
|
|
233
|
+
parts.push("--env ".concat(options.env));
|
|
234
|
+
}
|
|
235
|
+
parts.push(command);
|
|
236
|
+
return parts.join(" ");
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Resolve CLI name from argv
|
|
240
|
+
*/
|
|
241
|
+
export function resolveCliName(argv) {
|
|
242
|
+
var _a;
|
|
243
|
+
var args = argv !== null && argv !== void 0 ? argv : process.argv;
|
|
244
|
+
if (args.length < 2)
|
|
245
|
+
return DEFAULT_CLI_NAME;
|
|
246
|
+
var scriptPath = args[1];
|
|
247
|
+
var scriptName = (_a = scriptPath.split("/").pop()) !== null && _a !== void 0 ? _a : DEFAULT_CLI_NAME;
|
|
248
|
+
// Remove common extensions
|
|
249
|
+
return scriptName.replace(/\.(js|ts|mjs|cjs)$/, "");
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Check if running interactively
|
|
253
|
+
*/
|
|
254
|
+
export function isInteractive() {
|
|
255
|
+
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Format bytes to human readable string
|
|
259
|
+
*/
|
|
260
|
+
export function formatBytes(bytes) {
|
|
261
|
+
var units = ["B", "KB", "MB", "GB", "TB"];
|
|
262
|
+
var unitIndex = 0;
|
|
263
|
+
var value = bytes;
|
|
264
|
+
while (value >= 1024 && unitIndex < units.length - 1) {
|
|
265
|
+
value /= 1024;
|
|
266
|
+
unitIndex++;
|
|
267
|
+
}
|
|
268
|
+
return "".concat(value.toFixed(unitIndex === 0 ? 0 : 1), " ").concat(units[unitIndex]);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Format duration to human readable string
|
|
272
|
+
*/
|
|
273
|
+
export function formatDuration(ms) {
|
|
274
|
+
if (ms < 1000)
|
|
275
|
+
return "".concat(ms, "ms");
|
|
276
|
+
if (ms < 60000)
|
|
277
|
+
return "".concat((ms / 1000).toFixed(1), "s");
|
|
278
|
+
if (ms < 3600000)
|
|
279
|
+
return "".concat((ms / 60000).toFixed(1), "m");
|
|
280
|
+
return "".concat((ms / 3600000).toFixed(1), "h");
|
|
281
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elizaos/plugin-cli",
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
4
|
+
"description": "CLI framework plugin for ElizaOS agents - provides command registration, execution, and utilities",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"build:watch": "tsc --watch",
|
|
21
|
+
"dev": "tsc --watch",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"lint": "bunx @biomejs/biome check --write --unsafe .",
|
|
24
|
+
"lint:check": "bunx @biomejs/biome check .",
|
|
25
|
+
"format": "bunx @biomejs/biome format --write .",
|
|
26
|
+
"format:check": "bunx @biomejs/biome format .",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@elizaos/core": "2.0.0-alpha.3",
|
|
31
|
+
"commander": "^12.1.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@elizaos/core": "2.0.0-alpha.3"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"typescript": "^5.7.3",
|
|
38
|
+
"vitest": "^3.0.5",
|
|
39
|
+
"@biomejs/biome": "^2.3.11"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"elizaos",
|
|
43
|
+
"plugin",
|
|
44
|
+
"cli",
|
|
45
|
+
"command-line",
|
|
46
|
+
"terminal"
|
|
47
|
+
],
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"agentConfig": {
|
|
53
|
+
"pluginType": "elizaos:plugin:1.0.0",
|
|
54
|
+
"pluginParameters": {
|
|
55
|
+
"CLI_NAME": {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"description": "CLI command name",
|
|
58
|
+
"required": false,
|
|
59
|
+
"sensitive": false
|
|
60
|
+
},
|
|
61
|
+
"CLI_VERSION": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"description": "CLI version string",
|
|
64
|
+
"required": false,
|
|
65
|
+
"sensitive": false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|