@elizaos/plugin-cli 2.0.0-beta.1 → 2.0.3-beta.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shaw Walters and elizaOS Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # @elizaos/plugin-cli
2
+
3
+ CLI framework plugin for elizaOS agents. Provides a Commander-based command registry, TTY-aware progress reporting, and common helpers (duration parsing, byte formatting) for building agent-driven CLI tools.
4
+
5
+ ## What it does
6
+
7
+ - Maintains a module-level registry of `CliCommand` objects that other plugins or host code populate.
8
+ - Assembles a Commander `Command` tree from the registry via `buildProgram` / `runCli`.
9
+ - Offers a TTY-aware spinner (`createProgressReporter`, `withProgress`) that degrades to plain log lines in non-interactive environments.
10
+ - Ships parsing and formatting helpers for durations (`parseDurationMs`, `formatDuration`) and byte sizes (`formatBytes`).
11
+
12
+ The plugin object (`cliPlugin`) registers no actions, providers, services, or routes. Its value is the exported API that other code calls.
13
+
14
+ ## Capabilities
15
+
16
+ | Export | Description |
17
+ |--------|-------------|
18
+ | `buildProgram(options?)` | Builds a Commander program from all registered commands |
19
+ | `runCli(argv?, options?)` | Builds and runs the program against `argv` (defaults to `process.argv`) |
20
+ | `registerCliCommand(cmd)` | Register a `CliCommand` in the shared registry |
21
+ | `defineCliCommand(...)` | Factory to construct a `CliCommand` |
22
+ | `unregisterCliCommand(name)` | Remove a command from the registry |
23
+ | `listCliCommands()` | Returns all registered commands sorted by `priority` |
24
+ | `addSubcommand(parent, name, desc)` | Attach a subcommand to an existing Commander command |
25
+ | `createProgressReporter(deps, options?)` | TTY-aware spinner / progress reporter |
26
+ | `withProgress(deps, message, fn)` | Run an async function wrapped with start/success/fail reporting |
27
+ | `parseDurationMs(input)` | Parse `"1s"`, `"5m"`, `"2h"`, `"7d"`, bare ms strings |
28
+ | `parseTimeoutMs(input?, defaultMs)` | `parseDurationMs` with a default fallback |
29
+ | `formatDuration(ms)` | Milliseconds → human-readable string |
30
+ | `formatBytes(bytes)` | Bytes → human-readable string |
31
+ | `isInteractive()` | Returns `true` when both stdin and stdout are TTYs |
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ bun add @elizaos/plugin-cli
37
+ ```
38
+
39
+ Add to your agent's plugin list:
40
+
41
+ ```typescript
42
+ import { cliPlugin } from "@elizaos/plugin-cli";
43
+
44
+ export const character = {
45
+ plugins: [cliPlugin],
46
+ // ...
47
+ };
48
+ ```
49
+
50
+ ## Registering commands
51
+
52
+ ```typescript
53
+ import { defineCliCommand, registerCliCommand, runCli } from "@elizaos/plugin-cli";
54
+
55
+ registerCliCommand(
56
+ defineCliCommand(
57
+ "greet",
58
+ "Print a greeting",
59
+ (ctx) => {
60
+ ctx.program
61
+ .command("greet")
62
+ .description("Print a greeting")
63
+ .argument("<name>", "Name to greet")
64
+ .action((name) => {
65
+ console.log(`Hello, ${name}!`);
66
+ });
67
+ },
68
+ ),
69
+ );
70
+
71
+ await runCli(process.argv, { name: "myapp", version: "1.0.0" });
72
+ ```
73
+
74
+ ## Configuration
75
+
76
+ | Variable | Required | Default | Description |
77
+ |----------|----------|---------|-------------|
78
+ | `CLI_NAME` | No | `"elizaos"` | CLI binary name in help output |
79
+ | `CLI_VERSION` | No | `"1.0.0"` | Version string shown by `--version` |
80
+
81
+ Pass directly to `buildProgram` / `runCli` as options (`{ name, version }`). These values are declared in `agentConfig.pluginParameters` but are not read from `process.env` — the `init` function does not use its config parameter.
82
+
83
+ ## Using the progress reporter
84
+
85
+ ```typescript
86
+ import { createDefaultDeps, withProgress } from "@elizaos/plugin-cli";
87
+
88
+ const deps = createDefaultDeps();
89
+
90
+ await withProgress(deps, "Fetching data", async () => {
91
+ await fetchSomething();
92
+ });
93
+ // Prints spinner while running, then "✓ Fetching data" or "✗ <error message>"
94
+ ```
95
+
96
+ ## Duration parsing
97
+
98
+ ```typescript
99
+ import { parseDurationMs } from "@elizaos/plugin-cli";
100
+
101
+ parseDurationMs("5m"); // { ms: 300000, valid: true, original: "5m" }
102
+ parseDurationMs("30s"); // { ms: 30000, valid: true, original: "30s" }
103
+ parseDurationMs("bad"); // { ms: 0, valid: false, original: "bad" }
104
+ ```
105
+
106
+ Supported units: `ms`, `s`/`sec`/`second(s)`, `m`/`min`/`minute(s)`, `h`/`hr`/`hour(s)`, `d`/`day(s)`. Plain integers are treated as milliseconds.
107
+
108
+ ## Notes
109
+
110
+ - The command registry is module-level state shared across all imports in the same process. In tests, call `clearCliCommands()` in `beforeEach` / `afterEach`.
111
+ - All commands must be registered before `buildProgram` / `runCli` is called.
112
+ - The progress spinner writes ANSI escape sequences directly to `process.stdout` when running in a TTY; it degrades gracefully in CI and piped output.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-cli",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.3-beta.2",
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",
@@ -8,8 +8,24 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
+ "eliza-source": {
12
+ "types": "./src/index.ts",
13
+ "import": "./src/index.ts",
14
+ "default": "./src/index.ts"
15
+ },
11
16
  "import": "./dist/index.js",
12
17
  "default": "./dist/index.js"
18
+ },
19
+ "./*.css": "./dist/*.css",
20
+ "./*": {
21
+ "types": "./dist/*.d.ts",
22
+ "eliza-source": {
23
+ "types": "./src/*.ts",
24
+ "import": "./src/*.ts",
25
+ "default": "./src/*.ts"
26
+ },
27
+ "import": "./dist/*.js",
28
+ "default": "./dist/*.js"
13
29
  }
14
30
  },
15
31
  "files": [
@@ -24,11 +40,11 @@
24
40
  "lint:check": "bunx @biomejs/biome check .",
25
41
  "format": "bunx @biomejs/biome format --write .",
26
42
  "format:check": "bunx @biomejs/biome format .",
27
- "typecheck": "tsc --noEmit"
43
+ "typecheck": "tsgo --noEmit"
28
44
  },
29
45
  "dependencies": {
30
- "@elizaos/core": "2.0.0-beta.1",
31
- "commander": "^14.0.0"
46
+ "@elizaos/core": "2.0.3-beta.2",
47
+ "commander": "^15.0.0"
32
48
  },
33
49
  "devDependencies": {
34
50
  "@biomejs/biome": "^2.4.14",
@@ -63,5 +79,6 @@
63
79
  "sensitive": false
64
80
  }
65
81
  }
66
- }
82
+ },
83
+ "gitHead": "82fe0f44215954c2417328203f5bd6510985c1fc"
67
84
  }
package/dist/index.d.ts DELETED
@@ -1,65 +0,0 @@
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
@@ -1 +0,0 @@
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,EACN,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,eAAe,CAAC;AAEvB,cAAc,YAAY,CAAC;AAG3B,OAAO,EACN,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,YAAY,GACZ,MAAM,YAAY,CAAC;AAUpB;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,aAAa,GAAG,IAAI,CAAC;CACxC,GAAG,OAAO,CAoBV;AAED;;GAEG;AACH,wBAAsB,MAAM,CAC3B,IAAI,CAAC,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE;IACT,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,aAAa,GAAG,IAAI,CAAC;CACxC,GACC,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 DELETED
@@ -1,113 +0,0 @@
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 { logger } from "@elizaos/core";
13
- import { Command } from "commander";
14
- // Registry
15
- export { addSubcommand, clearCliCommands, defineCliCommand, getCliCommand, listCliCommands, registerAllCommands, registerCliCommand, unregisterCliCommand, } from "./registry.js";
16
- // Types
17
- export * from "./types.js";
18
- // Utils
19
- export { createDefaultDeps, createProgressReporter, DEFAULT_CLI_NAME, DEFAULT_CLI_VERSION, formatBytes, formatCliCommand, formatDuration, isInteractive, parseDurationMs, parseTimeoutMs, resolveCliName, withProgress, } from "./utils.js";
20
- import { listCliCommands, registerAllCommands } from "./registry.js";
21
- import { DEFAULT_CLI_NAME, DEFAULT_CLI_VERSION, resolveCliName, } from "./utils.js";
22
- /**
23
- * Build the Commander program with all registered commands
24
- */
25
- export function buildProgram(options) {
26
- const cliName = options?.name ?? resolveCliName();
27
- const version = options?.version ?? DEFAULT_CLI_VERSION;
28
- const program = new Command()
29
- .name(cliName)
30
- .version(version)
31
- .description(`${cliName} - ElizaOS agent CLI`);
32
- const ctx = {
33
- program,
34
- getRuntime: options?.getRuntime,
35
- cliName,
36
- version,
37
- };
38
- // Register all commands
39
- registerAllCommands(ctx);
40
- return program;
41
- }
42
- /**
43
- * Run the CLI with the given arguments
44
- */
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;
55
- }
56
- }
57
- throw error;
58
- }
59
- }
60
- /**
61
- * CLI Plugin for ElizaOS
62
- *
63
- * Provides CLI command infrastructure for the agent runtime.
64
- *
65
- * Configuration:
66
- * - CLI_NAME: CLI command name (default: "elizaos")
67
- * - CLI_VERSION: CLI version string
68
- *
69
- * @example
70
- * ```typescript
71
- * import { cliPlugin, buildProgram, registerCliCommand, defineCliCommand } from '@elizaos/plugin-cli';
72
- *
73
- * // Register a custom command
74
- * registerCliCommand(defineCliCommand(
75
- * 'mycommand',
76
- * 'My custom command',
77
- * (ctx) => {
78
- * ctx.program.command('mycommand')
79
- * .description('My custom command')
80
- * .action(() => console.log('Hello!'));
81
- * }
82
- * ));
83
- *
84
- * // Build and run
85
- * const program = buildProgram();
86
- * await program.parseAsync(process.argv);
87
- * ```
88
- */
89
- export const cliPlugin = {
90
- name: "cli",
91
- description: "CLI framework plugin for command registration and execution",
92
- providers: [],
93
- actions: [],
94
- services: [],
95
- routes: [],
96
- config: {
97
- CLI_NAME: DEFAULT_CLI_NAME,
98
- CLI_VERSION: DEFAULT_CLI_VERSION,
99
- },
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
- }
109
- },
110
- };
111
- export default cliPlugin;
112
- // Re-export Command for convenience
113
- export { Command } from "commander";
@@ -1,43 +0,0 @@
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
@@ -1 +0,0 @@
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,CAC/B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,CAAC,EAAE;IACT,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,GACC,UAAU,CAQZ;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GACjB,OAAO,CAET"}
package/dist/registry.js DELETED
@@ -1,76 +0,0 @@
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
- const 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 "${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((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
37
- }
38
- /**
39
- * Register all commands with the program
40
- */
41
- export function registerAllCommands(ctx) {
42
- const sorted = listCliCommands();
43
- for (const command of sorted) {
44
- try {
45
- command.register(ctx);
46
- logger.debug(`[CLI] Registered command: ${command.name}`);
47
- }
48
- catch (error) {
49
- logger.error(`[CLI] Failed to register command "${command.name}":`, error instanceof Error ? error.message : String(error));
50
- }
51
- }
52
- }
53
- /**
54
- * Clear all registered commands (for testing)
55
- */
56
- export function clearCliCommands() {
57
- commands.clear();
58
- }
59
- /**
60
- * Helper to create a CLI command definition
61
- */
62
- export function defineCliCommand(name, description, register, options) {
63
- return {
64
- name,
65
- description,
66
- register,
67
- aliases: options?.aliases,
68
- priority: options?.priority,
69
- };
70
- }
71
- /**
72
- * Helper to create a subcommand on an existing command
73
- */
74
- export function addSubcommand(parent, name, description) {
75
- return parent.command(name).description(description);
76
- }
package/dist/types.d.ts DELETED
@@ -1,127 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
package/dist/types.js DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * CLI plugin types
3
- *
4
- * Core types for CLI command registration and execution.
5
- */
6
- export {};
package/dist/utils.d.ts DELETED
@@ -1,66 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACX,OAAO,EACP,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,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,CACrC,IAAI,EAAE,OAAO,EACb,OAAO,CAAC,EAAE,eAAe,GACvB,gBAAgB,CA+DlB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,CAAC,EACnC,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,EACf,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAClB,OAAO,CAAC,CAAC,CAAC,CAWZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAuD7D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,SAAS,EAAE,MAAM,GACf,MAAM,CAIR;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IACT,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,GACC,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 DELETED
@@ -1,229 +0,0 @@
1
- /**
2
- * CLI utilities
3
- *
4
- * Common utilities for CLI operations.
5
- */
6
- /**
7
- * Default CLI name
8
- */
9
- export const DEFAULT_CLI_NAME = "elizaos";
10
- /**
11
- * Default CLI version
12
- */
13
- export const DEFAULT_CLI_VERSION = "1.0.0";
14
- /**
15
- * Create default CLI dependencies
16
- */
17
- export function createDefaultDeps() {
18
- return {
19
- log: (message) => console.log(message),
20
- error: (message) => console.error(message),
21
- exit: (code) => process.exit(code),
22
- };
23
- }
24
- /**
25
- * Create a progress reporter
26
- */
27
- export function createProgressReporter(deps, options) {
28
- let running = false;
29
- let intervalId = null;
30
- const spinnerFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
31
- let frameIndex = 0;
32
- let currentMessage = options?.message ?? "";
33
- const clearLine = () => {
34
- if (process.stdout.isTTY) {
35
- process.stdout.write("\r\x1b[K");
36
- }
37
- };
38
- const writeSpinner = () => {
39
- if (process.stdout.isTTY && options?.spinner !== false) {
40
- clearLine();
41
- process.stdout.write(`${spinnerFrames[frameIndex]} ${currentMessage}`);
42
- frameIndex = (frameIndex + 1) % spinnerFrames.length;
43
- }
44
- };
45
- return {
46
- start(message) {
47
- currentMessage = message;
48
- running = true;
49
- if (options?.spinner !== false && process.stdout.isTTY) {
50
- writeSpinner();
51
- intervalId = setInterval(writeSpinner, 80);
52
- }
53
- else {
54
- deps.log(message);
55
- }
56
- },
57
- update(message) {
58
- currentMessage = message;
59
- if (!running && !process.stdout.isTTY) {
60
- deps.log(message);
61
- }
62
- },
63
- success(message) {
64
- this.stop();
65
- if (process.stdout.isTTY) {
66
- clearLine();
67
- }
68
- deps.log(`✓ ${message}`);
69
- },
70
- fail(message) {
71
- this.stop();
72
- if (process.stdout.isTTY) {
73
- clearLine();
74
- }
75
- deps.error(`✗ ${message}`);
76
- },
77
- stop() {
78
- running = false;
79
- if (intervalId) {
80
- clearInterval(intervalId);
81
- intervalId = null;
82
- }
83
- if (process.stdout.isTTY) {
84
- clearLine();
85
- }
86
- },
87
- };
88
- }
89
- /**
90
- * Execute with progress reporting
91
- */
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
- }
104
- }
105
- /**
106
- * Parse a duration string to milliseconds
107
- *
108
- * Supports formats like:
109
- * - "1s", "30s" (seconds)
110
- * - "1m", "5m" (minutes)
111
- * - "1h", "2h" (hours)
112
- * - "1d", "7d" (days)
113
- * - "1000" (milliseconds)
114
- */
115
- export function parseDurationMs(input) {
116
- const trimmed = input.trim().toLowerCase();
117
- // Check for number only (milliseconds)
118
- const numOnly = parseInt(trimmed, 10);
119
- if (!Number.isNaN(numOnly) && String(numOnly) === trimmed) {
120
- return { ms: numOnly, original: input, valid: true };
121
- }
122
- // Parse with unit
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)?$/);
124
- if (!match) {
125
- return { ms: 0, original: input, valid: false };
126
- }
127
- const value = parseFloat(match[1]);
128
- const unit = match[2] ?? "ms";
129
- let multiplier;
130
- switch (unit) {
131
- case "ms":
132
- case "millisecond":
133
- case "milliseconds":
134
- multiplier = 1;
135
- break;
136
- case "s":
137
- case "sec":
138
- case "second":
139
- case "seconds":
140
- multiplier = 1000;
141
- break;
142
- case "m":
143
- case "min":
144
- case "minute":
145
- case "minutes":
146
- multiplier = 60 * 1000;
147
- break;
148
- case "h":
149
- case "hr":
150
- case "hour":
151
- case "hours":
152
- multiplier = 60 * 60 * 1000;
153
- break;
154
- case "d":
155
- case "day":
156
- case "days":
157
- multiplier = 24 * 60 * 60 * 1000;
158
- break;
159
- default:
160
- return { ms: 0, original: input, valid: false };
161
- }
162
- return { ms: Math.round(value * multiplier), original: input, valid: true };
163
- }
164
- /**
165
- * Parse a timeout string with defaults
166
- */
167
- export function parseTimeoutMs(input, defaultMs) {
168
- if (!input)
169
- return defaultMs;
170
- const parsed = parseDurationMs(input);
171
- return parsed.valid ? parsed.ms : defaultMs;
172
- }
173
- /**
174
- * Format a CLI command with profile/env context
175
- */
176
- export function formatCliCommand(command, options) {
177
- const parts = [options?.cliName ?? DEFAULT_CLI_NAME];
178
- if (options?.profile) {
179
- parts.push(`--profile ${options.profile}`);
180
- }
181
- if (options?.env) {
182
- parts.push(`--env ${options.env}`);
183
- }
184
- parts.push(command);
185
- return parts.join(" ");
186
- }
187
- /**
188
- * Resolve CLI name from argv
189
- */
190
- export function resolveCliName(argv) {
191
- const args = argv ?? process.argv;
192
- if (args.length < 2)
193
- return DEFAULT_CLI_NAME;
194
- const scriptPath = args[1];
195
- const scriptName = scriptPath.split("/").pop() ?? DEFAULT_CLI_NAME;
196
- // Remove common extensions
197
- return scriptName.replace(/\.(js|ts|mjs|cjs)$/, "");
198
- }
199
- /**
200
- * Check if running interactively
201
- */
202
- export function isInteractive() {
203
- return process.stdin.isTTY === true && process.stdout.isTTY === true;
204
- }
205
- /**
206
- * Format bytes to human readable string
207
- */
208
- export function formatBytes(bytes) {
209
- const units = ["B", "KB", "MB", "GB", "TB"];
210
- let unitIndex = 0;
211
- let value = bytes;
212
- while (value >= 1024 && unitIndex < units.length - 1) {
213
- value /= 1024;
214
- unitIndex++;
215
- }
216
- return `${value.toFixed(unitIndex === 0 ? 0 : 1)} ${units[unitIndex]}`;
217
- }
218
- /**
219
- * Format duration to human readable string
220
- */
221
- export function formatDuration(ms) {
222
- if (ms < 1000)
223
- return `${ms}ms`;
224
- if (ms < 60000)
225
- return `${(ms / 1000).toFixed(1)}s`;
226
- if (ms < 3600000)
227
- return `${(ms / 60000).toFixed(1)}m`;
228
- return `${(ms / 3600000).toFixed(1)}h`;
229
- }