@elizaos/plugin-cli 2.0.0-alpha.9 → 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 +21 -0
- package/README.md +112 -0
- package/package.json +25 -11
- package/dist/index.d.ts +0 -90
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -113
- package/dist/registry.d.ts +0 -52
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js +0 -76
- package/dist/types.d.ts +0 -127
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/utils.d.ts +0 -84
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -229
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.
|
|
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": [
|
|
@@ -19,24 +35,21 @@
|
|
|
19
35
|
"build": "tsc",
|
|
20
36
|
"build:watch": "tsc --watch",
|
|
21
37
|
"dev": "tsc --watch",
|
|
22
|
-
"test": "vitest run
|
|
38
|
+
"test": "vitest run",
|
|
23
39
|
"lint": "bunx @biomejs/biome check --write --unsafe .",
|
|
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": "
|
|
43
|
+
"typecheck": "tsgo --noEmit"
|
|
28
44
|
},
|
|
29
45
|
"dependencies": {
|
|
30
|
-
"@elizaos/core": "2.0.
|
|
31
|
-
"commander": "^
|
|
32
|
-
},
|
|
33
|
-
"peerDependencies": {
|
|
34
|
-
"@elizaos/core": "2.0.0-alpha.3"
|
|
46
|
+
"@elizaos/core": "2.0.3-beta.2",
|
|
47
|
+
"commander": "^15.0.0"
|
|
35
48
|
},
|
|
36
49
|
"devDependencies": {
|
|
37
|
-
"@biomejs/biome": "^2.
|
|
50
|
+
"@biomejs/biome": "^2.4.14",
|
|
38
51
|
"strip-literal": "^3.1.0",
|
|
39
|
-
"typescript": "^
|
|
52
|
+
"typescript": "^6.0.3",
|
|
40
53
|
"vitest": "^4.0.18"
|
|
41
54
|
},
|
|
42
55
|
"keywords": [
|
|
@@ -66,5 +79,6 @@
|
|
|
66
79
|
"sensitive": false
|
|
67
80
|
}
|
|
68
81
|
}
|
|
69
|
-
}
|
|
82
|
+
},
|
|
83
|
+
"gitHead": "82fe0f44215954c2417328203f5bd6510985c1fc"
|
|
70
84
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,90 +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 {
|
|
15
|
-
addSubcommand,
|
|
16
|
-
clearCliCommands,
|
|
17
|
-
defineCliCommand,
|
|
18
|
-
getCliCommand,
|
|
19
|
-
listCliCommands,
|
|
20
|
-
registerAllCommands,
|
|
21
|
-
registerCliCommand,
|
|
22
|
-
unregisterCliCommand,
|
|
23
|
-
} from "./registry.js";
|
|
24
|
-
export * from "./types.js";
|
|
25
|
-
export {
|
|
26
|
-
createDefaultDeps,
|
|
27
|
-
createProgressReporter,
|
|
28
|
-
DEFAULT_CLI_NAME,
|
|
29
|
-
DEFAULT_CLI_VERSION,
|
|
30
|
-
formatBytes,
|
|
31
|
-
formatCliCommand,
|
|
32
|
-
formatDuration,
|
|
33
|
-
isInteractive,
|
|
34
|
-
parseDurationMs,
|
|
35
|
-
parseTimeoutMs,
|
|
36
|
-
resolveCliName,
|
|
37
|
-
withProgress,
|
|
38
|
-
} from "./utils.js";
|
|
39
|
-
/**
|
|
40
|
-
* Build the Commander program with all registered commands
|
|
41
|
-
*/
|
|
42
|
-
export declare function buildProgram(options?: {
|
|
43
|
-
name?: string;
|
|
44
|
-
version?: string;
|
|
45
|
-
getRuntime?: () => IAgentRuntime | null;
|
|
46
|
-
}): Command;
|
|
47
|
-
/**
|
|
48
|
-
* Run the CLI with the given arguments
|
|
49
|
-
*/
|
|
50
|
-
export declare function runCli(
|
|
51
|
-
argv?: string[],
|
|
52
|
-
options?: {
|
|
53
|
-
name?: string;
|
|
54
|
-
version?: string;
|
|
55
|
-
getRuntime?: () => IAgentRuntime | null;
|
|
56
|
-
},
|
|
57
|
-
): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* CLI Plugin for ElizaOS
|
|
60
|
-
*
|
|
61
|
-
* Provides CLI command infrastructure for the agent runtime.
|
|
62
|
-
*
|
|
63
|
-
* Configuration:
|
|
64
|
-
* - CLI_NAME: CLI command name (default: "elizaos")
|
|
65
|
-
* - CLI_VERSION: CLI version string
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* import { cliPlugin, buildProgram, registerCliCommand, defineCliCommand } from '@elizaos/plugin-cli';
|
|
70
|
-
*
|
|
71
|
-
* // Register a custom command
|
|
72
|
-
* registerCliCommand(defineCliCommand(
|
|
73
|
-
* 'mycommand',
|
|
74
|
-
* 'My custom command',
|
|
75
|
-
* (ctx) => {
|
|
76
|
-
* ctx.program.command('mycommand')
|
|
77
|
-
* .description('My custom command')
|
|
78
|
-
* .action(() => console.log('Hello!'));
|
|
79
|
-
* }
|
|
80
|
-
* ));
|
|
81
|
-
*
|
|
82
|
-
* // Build and run
|
|
83
|
-
* const program = buildProgram();
|
|
84
|
-
* await program.parseAsync(process.argv);
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
export declare const cliPlugin: Plugin;
|
|
88
|
-
export default cliPlugin;
|
|
89
|
-
export { Command } from "commander";
|
|
90
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -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";
|
package/dist/registry.d.ts
DELETED
|
@@ -1,52 +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(
|
|
36
|
-
name: string,
|
|
37
|
-
description: string,
|
|
38
|
-
register: CliRegistrationFn,
|
|
39
|
-
options?: {
|
|
40
|
-
aliases?: string[];
|
|
41
|
-
priority?: number;
|
|
42
|
-
},
|
|
43
|
-
): CliCommand;
|
|
44
|
-
/**
|
|
45
|
-
* Helper to create a subcommand on an existing command
|
|
46
|
-
*/
|
|
47
|
-
export declare function addSubcommand(
|
|
48
|
-
parent: Command,
|
|
49
|
-
name: string,
|
|
50
|
-
description: string,
|
|
51
|
-
): Command;
|
|
52
|
-
//# sourceMappingURL=registry.d.ts.map
|
package/dist/registry.d.ts.map
DELETED
|
@@ -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
|
package/dist/types.d.ts.map
DELETED
|
@@ -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
package/dist/utils.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI utilities
|
|
3
|
-
*
|
|
4
|
-
* Common utilities for CLI operations.
|
|
5
|
-
*/
|
|
6
|
-
import type {
|
|
7
|
-
CliDeps,
|
|
8
|
-
ParsedDuration,
|
|
9
|
-
ProgressOptions,
|
|
10
|
-
ProgressReporter,
|
|
11
|
-
} from "./types.js";
|
|
12
|
-
/**
|
|
13
|
-
* Default CLI name
|
|
14
|
-
*/
|
|
15
|
-
export declare const DEFAULT_CLI_NAME = "elizaos";
|
|
16
|
-
/**
|
|
17
|
-
* Default CLI version
|
|
18
|
-
*/
|
|
19
|
-
export declare const DEFAULT_CLI_VERSION = "1.0.0";
|
|
20
|
-
/**
|
|
21
|
-
* Create default CLI dependencies
|
|
22
|
-
*/
|
|
23
|
-
export declare function createDefaultDeps(): CliDeps;
|
|
24
|
-
/**
|
|
25
|
-
* Create a progress reporter
|
|
26
|
-
*/
|
|
27
|
-
export declare function createProgressReporter(
|
|
28
|
-
deps: CliDeps,
|
|
29
|
-
options?: ProgressOptions,
|
|
30
|
-
): ProgressReporter;
|
|
31
|
-
/**
|
|
32
|
-
* Execute with progress reporting
|
|
33
|
-
*/
|
|
34
|
-
export declare function withProgress<T>(
|
|
35
|
-
deps: CliDeps,
|
|
36
|
-
message: string,
|
|
37
|
-
fn: () => Promise<T>,
|
|
38
|
-
): Promise<T>;
|
|
39
|
-
/**
|
|
40
|
-
* Parse a duration string to milliseconds
|
|
41
|
-
*
|
|
42
|
-
* Supports formats like:
|
|
43
|
-
* - "1s", "30s" (seconds)
|
|
44
|
-
* - "1m", "5m" (minutes)
|
|
45
|
-
* - "1h", "2h" (hours)
|
|
46
|
-
* - "1d", "7d" (days)
|
|
47
|
-
* - "1000" (milliseconds)
|
|
48
|
-
*/
|
|
49
|
-
export declare function parseDurationMs(input: string): ParsedDuration;
|
|
50
|
-
/**
|
|
51
|
-
* Parse a timeout string with defaults
|
|
52
|
-
*/
|
|
53
|
-
export declare function parseTimeoutMs(
|
|
54
|
-
input: string | undefined,
|
|
55
|
-
defaultMs: number,
|
|
56
|
-
): number;
|
|
57
|
-
/**
|
|
58
|
-
* Format a CLI command with profile/env context
|
|
59
|
-
*/
|
|
60
|
-
export declare function formatCliCommand(
|
|
61
|
-
command: string,
|
|
62
|
-
options?: {
|
|
63
|
-
cliName?: string;
|
|
64
|
-
profile?: string;
|
|
65
|
-
env?: string;
|
|
66
|
-
},
|
|
67
|
-
): string;
|
|
68
|
-
/**
|
|
69
|
-
* Resolve CLI name from argv
|
|
70
|
-
*/
|
|
71
|
-
export declare function resolveCliName(argv?: string[]): string;
|
|
72
|
-
/**
|
|
73
|
-
* Check if running interactively
|
|
74
|
-
*/
|
|
75
|
-
export declare function isInteractive(): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Format bytes to human readable string
|
|
78
|
-
*/
|
|
79
|
-
export declare function formatBytes(bytes: number): string;
|
|
80
|
-
/**
|
|
81
|
-
* Format duration to human readable string
|
|
82
|
-
*/
|
|
83
|
-
export declare function formatDuration(ms: number): string;
|
|
84
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
DELETED
|
@@ -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
|
-
}
|