@elizaos/plugin-cli 2.0.0-alpha.3 → 2.0.0-alpha.4

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.js CHANGED
@@ -9,42 +9,6 @@
9
9
  * - Duration/timeout parsing
10
10
  * - Common CLI dependencies
11
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
12
  import { logger } from "@elizaos/core";
49
13
  import { Command } from "commander";
50
14
  // Registry
@@ -59,18 +23,17 @@ import { DEFAULT_CLI_NAME, DEFAULT_CLI_VERSION, resolveCliName, } from "./utils.
59
23
  * Build the Commander program with all registered commands
60
24
  */
61
25
  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()
26
+ const cliName = options?.name ?? resolveCliName();
27
+ const version = options?.version ?? DEFAULT_CLI_VERSION;
28
+ const program = new Command()
66
29
  .name(cliName)
67
30
  .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,
31
+ .description(`${cliName} - ElizaOS agent CLI`);
32
+ const ctx = {
33
+ program,
34
+ getRuntime: options?.getRuntime,
35
+ cliName,
36
+ version,
74
37
  };
75
38
  // Register all commands
76
39
  registerAllCommands(ctx);
@@ -79,33 +42,20 @@ export function buildProgram(options) {
79
42
  /**
80
43
  * Run the CLI with the given arguments
81
44
  */
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*/];
45
+ export async function runCli(argv, options) {
46
+ const program = buildProgram(options);
47
+ try {
48
+ await program.parseAsync(argv ?? process.argv);
49
+ }
50
+ catch (error) {
51
+ if (error instanceof Error) {
52
+ // Commander throws an error for --help and --version
53
+ if (error.message.includes("outputHelp")) {
54
+ return;
106
55
  }
107
- });
108
- });
56
+ }
57
+ throw error;
58
+ }
109
59
  }
110
60
  /**
111
61
  * CLI Plugin for ElizaOS
@@ -136,7 +86,7 @@ export function runCli(argv, options) {
136
86
  * await program.parseAsync(process.argv);
137
87
  * ```
138
88
  */
139
- export var cliPlugin = {
89
+ export const cliPlugin = {
140
90
  name: "cli",
141
91
  description: "CLI framework plugin for command registration and execution",
142
92
  providers: [],
@@ -147,21 +97,15 @@ export var cliPlugin = {
147
97
  CLI_NAME: DEFAULT_CLI_NAME,
148
98
  CLI_VERSION: DEFAULT_CLI_VERSION,
149
99
  },
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
- });
100
+ async init(_config, _runtime) {
101
+ try {
102
+ const commands = listCliCommands();
103
+ logger.info({ commandCount: commands.length }, "[CLIPlugin] Plugin initialized");
104
+ }
105
+ catch (error) {
106
+ logger.error("[CLIPlugin] Error initializing:", error instanceof Error ? error.message : String(error));
107
+ throw error;
108
+ }
165
109
  },
166
110
  };
167
111
  export default cliPlugin;
package/dist/registry.js CHANGED
@@ -7,13 +7,13 @@ import { logger } from "@elizaos/core";
7
7
  /**
8
8
  * Internal registry of CLI commands
9
9
  */
10
- var commands = new Map();
10
+ const commands = new Map();
11
11
  /**
12
12
  * Register a CLI command
13
13
  */
14
14
  export function registerCliCommand(command) {
15
15
  if (commands.has(command.name)) {
16
- logger.warn("[CLI] Command \"".concat(command.name, "\" already registered, replacing"));
16
+ logger.warn(`[CLI] Command "${command.name}" already registered, replacing`);
17
17
  }
18
18
  commands.set(command.name, command);
19
19
  }
@@ -33,21 +33,20 @@ export function getCliCommand(name) {
33
33
  * List all registered CLI commands
34
34
  */
35
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); });
36
+ return Array.from(commands.values()).sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
37
37
  }
38
38
  /**
39
39
  * Register all commands with the program
40
40
  */
41
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];
42
+ const sorted = listCliCommands();
43
+ for (const command of sorted) {
45
44
  try {
46
45
  command.register(ctx);
47
- logger.debug("[CLI] Registered command: ".concat(command.name));
46
+ logger.debug(`[CLI] Registered command: ${command.name}`);
48
47
  }
49
48
  catch (error) {
50
- logger.error("[CLI] Failed to register command \"".concat(command.name, "\":"), error instanceof Error ? error.message : String(error));
49
+ logger.error(`[CLI] Failed to register command "${command.name}":`, error instanceof Error ? error.message : String(error));
51
50
  }
52
51
  }
53
52
  }
@@ -62,11 +61,11 @@ export function clearCliCommands() {
62
61
  */
63
62
  export function defineCliCommand(name, description, register, options) {
64
63
  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,
64
+ name,
65
+ description,
66
+ register,
67
+ aliases: options?.aliases,
68
+ priority: options?.priority,
70
69
  };
71
70
  }
72
71
  /**
package/dist/utils.js CHANGED
@@ -3,87 +3,50 @@
3
3
  *
4
4
  * Common utilities for CLI operations.
5
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
6
  /**
43
7
  * Default CLI name
44
8
  */
45
- export var DEFAULT_CLI_NAME = "elizaos";
9
+ export const DEFAULT_CLI_NAME = "elizaos";
46
10
  /**
47
11
  * Default CLI version
48
12
  */
49
- export var DEFAULT_CLI_VERSION = "1.0.0";
13
+ export const DEFAULT_CLI_VERSION = "1.0.0";
50
14
  /**
51
15
  * Create default CLI dependencies
52
16
  */
53
17
  export function createDefaultDeps() {
54
18
  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); },
19
+ log: (message) => console.log(message),
20
+ error: (message) => console.error(message),
21
+ exit: (code) => process.exit(code),
58
22
  };
59
23
  }
60
24
  /**
61
25
  * Create a progress reporter
62
26
  */
63
27
  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 () {
28
+ let running = false;
29
+ let intervalId = null;
30
+ const spinnerFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
31
+ let frameIndex = 0;
32
+ let currentMessage = options?.message ?? "";
33
+ const clearLine = () => {
71
34
  if (process.stdout.isTTY) {
72
35
  process.stdout.write("\r\x1b[K");
73
36
  }
74
37
  };
75
- var writeSpinner = function () {
76
- if (process.stdout.isTTY && (options === null || options === void 0 ? void 0 : options.spinner) !== false) {
38
+ const writeSpinner = () => {
39
+ if (process.stdout.isTTY && options?.spinner !== false) {
77
40
  clearLine();
78
- process.stdout.write("".concat(spinnerFrames[frameIndex], " ").concat(currentMessage));
41
+ process.stdout.write(`${spinnerFrames[frameIndex]} ${currentMessage}`);
79
42
  frameIndex = (frameIndex + 1) % spinnerFrames.length;
80
43
  }
81
44
  };
82
45
  return {
83
- start: function (message) {
46
+ start(message) {
84
47
  currentMessage = message;
85
48
  running = true;
86
- if ((options === null || options === void 0 ? void 0 : options.spinner) !== false && process.stdout.isTTY) {
49
+ if (options?.spinner !== false && process.stdout.isTTY) {
87
50
  writeSpinner();
88
51
  intervalId = setInterval(writeSpinner, 80);
89
52
  }
@@ -91,27 +54,27 @@ export function createProgressReporter(deps, options) {
91
54
  deps.log(message);
92
55
  }
93
56
  },
94
- update: function (message) {
57
+ update(message) {
95
58
  currentMessage = message;
96
59
  if (!running && !process.stdout.isTTY) {
97
60
  deps.log(message);
98
61
  }
99
62
  },
100
- success: function (message) {
63
+ success(message) {
101
64
  this.stop();
102
65
  if (process.stdout.isTTY) {
103
66
  clearLine();
104
67
  }
105
- deps.log("\u2713 ".concat(message));
68
+ deps.log(`✓ ${message}`);
106
69
  },
107
- fail: function (message) {
70
+ fail(message) {
108
71
  this.stop();
109
72
  if (process.stdout.isTTY) {
110
73
  clearLine();
111
74
  }
112
- deps.error("\u2717 ".concat(message));
75
+ deps.error(`✗ ${message}`);
113
76
  },
114
- stop: function () {
77
+ stop() {
115
78
  running = false;
116
79
  if (intervalId) {
117
80
  clearInterval(intervalId);
@@ -126,30 +89,18 @@ export function createProgressReporter(deps, options) {
126
89
  /**
127
90
  * Execute with progress reporting
128
91
  */
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
- });
92
+ export async function withProgress(deps, message, fn) {
93
+ const progress = createProgressReporter(deps, { message, spinner: true });
94
+ progress.start(message);
95
+ try {
96
+ const result = await fn();
97
+ progress.success(message);
98
+ return result;
99
+ }
100
+ catch (error) {
101
+ progress.fail(error instanceof Error ? error.message : String(error));
102
+ throw error;
103
+ }
153
104
  }
154
105
  /**
155
106
  * Parse a duration string to milliseconds
@@ -162,21 +113,20 @@ export function withProgress(deps, message, fn) {
162
113
  * - "1000" (milliseconds)
163
114
  */
164
115
  export function parseDurationMs(input) {
165
- var _a;
166
- var trimmed = input.trim().toLowerCase();
116
+ const trimmed = input.trim().toLowerCase();
167
117
  // Check for number only (milliseconds)
168
- var numOnly = parseInt(trimmed, 10);
118
+ const numOnly = parseInt(trimmed, 10);
169
119
  if (!Number.isNaN(numOnly) && String(numOnly) === trimmed) {
170
120
  return { ms: numOnly, original: input, valid: true };
171
121
  }
172
122
  // 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)?$/);
123
+ const 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
124
  if (!match) {
175
125
  return { ms: 0, original: input, valid: false };
176
126
  }
177
- var value = parseFloat(match[1]);
178
- var unit = (_a = match[2]) !== null && _a !== void 0 ? _a : "ms";
179
- var multiplier;
127
+ const value = parseFloat(match[1]);
128
+ const unit = match[2] ?? "ms";
129
+ let multiplier;
180
130
  switch (unit) {
181
131
  case "ms":
182
132
  case "millisecond":
@@ -217,20 +167,19 @@ export function parseDurationMs(input) {
217
167
  export function parseTimeoutMs(input, defaultMs) {
218
168
  if (!input)
219
169
  return defaultMs;
220
- var parsed = parseDurationMs(input);
170
+ const parsed = parseDurationMs(input);
221
171
  return parsed.valid ? parsed.ms : defaultMs;
222
172
  }
223
173
  /**
224
174
  * Format a CLI command with profile/env context
225
175
  */
226
176
  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));
177
+ const parts = [options?.cliName ?? DEFAULT_CLI_NAME];
178
+ if (options?.profile) {
179
+ parts.push(`--profile ${options.profile}`);
231
180
  }
232
- if (options === null || options === void 0 ? void 0 : options.env) {
233
- parts.push("--env ".concat(options.env));
181
+ if (options?.env) {
182
+ parts.push(`--env ${options.env}`);
234
183
  }
235
184
  parts.push(command);
236
185
  return parts.join(" ");
@@ -239,12 +188,11 @@ export function formatCliCommand(command, options) {
239
188
  * Resolve CLI name from argv
240
189
  */
241
190
  export function resolveCliName(argv) {
242
- var _a;
243
- var args = argv !== null && argv !== void 0 ? argv : process.argv;
191
+ const args = argv ?? process.argv;
244
192
  if (args.length < 2)
245
193
  return DEFAULT_CLI_NAME;
246
- var scriptPath = args[1];
247
- var scriptName = (_a = scriptPath.split("/").pop()) !== null && _a !== void 0 ? _a : DEFAULT_CLI_NAME;
194
+ const scriptPath = args[1];
195
+ const scriptName = scriptPath.split("/").pop() ?? DEFAULT_CLI_NAME;
248
196
  // Remove common extensions
249
197
  return scriptName.replace(/\.(js|ts|mjs|cjs)$/, "");
250
198
  }
@@ -258,24 +206,24 @@ export function isInteractive() {
258
206
  * Format bytes to human readable string
259
207
  */
260
208
  export function formatBytes(bytes) {
261
- var units = ["B", "KB", "MB", "GB", "TB"];
262
- var unitIndex = 0;
263
- var value = bytes;
209
+ const units = ["B", "KB", "MB", "GB", "TB"];
210
+ let unitIndex = 0;
211
+ let value = bytes;
264
212
  while (value >= 1024 && unitIndex < units.length - 1) {
265
213
  value /= 1024;
266
214
  unitIndex++;
267
215
  }
268
- return "".concat(value.toFixed(unitIndex === 0 ? 0 : 1), " ").concat(units[unitIndex]);
216
+ return `${value.toFixed(unitIndex === 0 ? 0 : 1)} ${units[unitIndex]}`;
269
217
  }
270
218
  /**
271
219
  * Format duration to human readable string
272
220
  */
273
221
  export function formatDuration(ms) {
274
222
  if (ms < 1000)
275
- return "".concat(ms, "ms");
223
+ return `${ms}ms`;
276
224
  if (ms < 60000)
277
- return "".concat((ms / 1000).toFixed(1), "s");
225
+ return `${(ms / 1000).toFixed(1)}s`;
278
226
  if (ms < 3600000)
279
- return "".concat((ms / 60000).toFixed(1), "m");
280
- return "".concat((ms / 3600000).toFixed(1), "h");
227
+ return `${(ms / 60000).toFixed(1)}m`;
228
+ return `${(ms / 3600000).toFixed(1)}h`;
281
229
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-cli",
3
- "version": "2.0.0-alpha.3",
3
+ "version": "2.0.0-alpha.4",
4
4
  "description": "CLI framework plugin for ElizaOS agents - provides command registration, execution, and utilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",