@actiondock/cli 2.0.12 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -34
- package/bin/ad.js +28 -41
- package/dist/commands/action/create.d.ts +9 -1
- package/dist/commands/action/create.js +120 -0
- package/dist/commands/add.d.ts +7 -0
- package/dist/commands/add.js +144 -0
- package/dist/commands/build.d.ts +2 -1
- package/dist/commands/build.js +83 -0
- package/dist/commands/config/delete.d.ts +9 -0
- package/dist/commands/config/delete.js +52 -0
- package/dist/commands/config/env.d.ts +9 -0
- package/dist/commands/config/env.js +85 -0
- package/dist/commands/config/get.d.ts +9 -0
- package/dist/commands/config/get.js +120 -0
- package/dist/commands/config/index.d.ts +9 -0
- package/dist/commands/config/index.js +23 -0
- package/dist/commands/config/list.d.ts +9 -0
- package/dist/commands/config/list.js +137 -0
- package/dist/commands/config/schema.d.ts +9 -0
- package/dist/commands/config/schema.js +121 -0
- package/dist/commands/config/set.d.ts +9 -0
- package/dist/commands/config/set.js +85 -0
- package/dist/commands/describe.d.ts +9 -0
- package/dist/commands/describe.js +68 -0
- package/dist/commands/doctor.d.ts +2 -1
- package/dist/commands/doctor.js +82 -0
- package/dist/commands/export.d.ts +2 -1
- package/dist/commands/export.js +212 -0
- package/dist/commands/generate.d.ts +9 -0
- package/dist/commands/generate.js +44 -0
- package/dist/commands/index.d.ts +31 -1
- package/dist/commands/index.js +111 -0
- package/dist/commands/info.d.ts +9 -2
- package/dist/commands/info.js +210 -0
- package/dist/commands/init.js +24 -0
- package/dist/commands/link.js +71 -0
- package/dist/commands/list.d.ts +9 -0
- package/dist/commands/list.js +77 -0
- package/dist/commands/mcp.d.ts +9 -2
- package/dist/commands/mcp.js +173 -0
- package/dist/commands/new.d.ts +9 -0
- package/dist/commands/new.js +33 -0
- package/dist/commands/pack.d.ts +3 -0
- package/dist/commands/pack.js +63 -0
- package/dist/commands/playbook.d.ts +7 -3
- package/dist/commands/playbook.js +433 -0
- package/dist/commands/profile.js +253 -0
- package/dist/commands/remove.d.ts +7 -0
- package/dist/commands/remove.js +118 -0
- package/dist/commands/run.d.ts +13 -0
- package/dist/commands/run.js +146 -0
- package/dist/commands/runs.d.ts +9 -2
- package/dist/commands/runs.js +245 -0
- package/dist/commands/serve.d.ts +9 -2
- package/dist/commands/serve.js +135 -0
- package/dist/commands/state-list.d.ts +24 -0
- package/dist/commands/state-list.js +82 -0
- package/dist/commands/state.d.ts +9 -2
- package/dist/commands/state.js +310 -0
- package/dist/commands/test.js +44 -0
- package/dist/commands/validate.d.ts +9 -0
- package/dist/commands/validate.js +106 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.js +103 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +41 -1000
- package/dist/prompt.d.ts +53 -0
- package/dist/prompt.js +192 -0
- package/dist/renderer.d.ts +197 -0
- package/dist/renderer.js +502 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/inspect.d.ts +23 -0
- package/dist/services/inspect.js +96 -0
- package/dist/standalone/index.d.ts +16 -0
- package/dist/standalone/index.js +22 -0
- package/dist/types.d.ts +132 -0
- package/dist/types.js +9 -0
- package/dist/utils/bytes.d.ts +1 -1
- package/dist/utils/bytes.js +1 -0
- package/dist/utils/duration.js +1 -0
- package/dist/utils/filter.d.ts +1 -1
- package/dist/utils/filter.js +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/spawn.d.ts +27 -0
- package/dist/utils/spawn.js +35 -0
- package/dist/utils/target.d.ts +45 -0
- package/dist/utils/target.js +78 -0
- package/dist/utils/utils.d.ts +38 -0
- package/dist/utils/utils.js +111 -0
- package/package.json +10 -12
- package/dist/commands/action/index.d.ts +0 -16
- package/dist/commands/action/list.d.ts +0 -5
- package/dist/commands/action/run.d.ts +0 -4
- package/dist/commands/action/show.d.ts +0 -5
- package/dist/commands/action/sync.d.ts +0 -2
- package/dist/commands/action/validate.d.ts +0 -5
- package/dist/commands/action.d.ts +0 -1
- package/dist/commands/config.d.ts +0 -2
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { ActionDefinition } from "@actiondock/sdk";
|
|
2
|
+
import type { ConfigItemDefinition } from "@actiondock/core";
|
|
3
|
+
/**
|
|
4
|
+
* 统一退出码定义(事实源位于 core 包 StandaloneDispatcher,此处仅 re-export 维持既有导入路径兼容)。
|
|
5
|
+
* - SUCCESS: 执行成功(0)
|
|
6
|
+
* - FAILURE: 业务或框架执行失败(1)
|
|
7
|
+
* - INVALID_ARGUMENT: 命令行参数或选项错误(2)
|
|
8
|
+
* - SIGINT: 进程接收中断信号退出(130)
|
|
9
|
+
*/
|
|
10
|
+
export declare const ExitCode: {
|
|
11
|
+
readonly SUCCESS: 0;
|
|
12
|
+
readonly FAILURE: 1;
|
|
13
|
+
readonly INVALID_ARGUMENT: 2;
|
|
14
|
+
readonly SIGINT: 130;
|
|
15
|
+
};
|
|
16
|
+
export type ExitCodeValue = (typeof ExitCode)[keyof typeof ExitCode];
|
|
17
|
+
/**
|
|
18
|
+
* 标准执行与数据信封接口。
|
|
19
|
+
*/
|
|
20
|
+
export interface Envelope<T = unknown> {
|
|
21
|
+
ok: boolean;
|
|
22
|
+
data?: T;
|
|
23
|
+
error?: {
|
|
24
|
+
code: string;
|
|
25
|
+
message: string;
|
|
26
|
+
details?: unknown;
|
|
27
|
+
};
|
|
28
|
+
meta?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 独立二进制运行模式声明。
|
|
32
|
+
*/
|
|
33
|
+
export interface StandaloneOptions {
|
|
34
|
+
/** 所属 Package ID */
|
|
35
|
+
packageId: string;
|
|
36
|
+
/** 版本号 */
|
|
37
|
+
version: string;
|
|
38
|
+
/** 描述信息 */
|
|
39
|
+
description?: string;
|
|
40
|
+
/** 声明的配置依赖字典 */
|
|
41
|
+
configDefs?: Record<string, ConfigItemDefinition>;
|
|
42
|
+
/** 内置动作定义映射或数组 */
|
|
43
|
+
actions: Map<string, ActionDefinition> | Array<{
|
|
44
|
+
id: string;
|
|
45
|
+
action: ActionDefinition;
|
|
46
|
+
} | (ActionDefinition & {
|
|
47
|
+
id: string;
|
|
48
|
+
})> | Record<string, ActionDefinition>;
|
|
49
|
+
/** 自定义数据目录 */
|
|
50
|
+
dataDir?: string;
|
|
51
|
+
/** 自定义 ActionDock 用户家目录 */
|
|
52
|
+
customHome?: string;
|
|
53
|
+
/** 自定义标准输出写入函数 */
|
|
54
|
+
stdout?: (msg: string) => void;
|
|
55
|
+
/** 自定义标准错误写入函数 */
|
|
56
|
+
stderr?: (msg: string) => void;
|
|
57
|
+
/** 是否采用纯内存运行模式 */
|
|
58
|
+
inMemory?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* CLI 上下文环境。
|
|
62
|
+
*/
|
|
63
|
+
export interface CliContext {
|
|
64
|
+
/** 独立运行模式配置 */
|
|
65
|
+
standalone?: StandaloneOptions;
|
|
66
|
+
/** 自定义数据目录 */
|
|
67
|
+
dataDir?: string;
|
|
68
|
+
/** 自定义 ActionDock 用户家目录(用于测试隔离与多租户环境) */
|
|
69
|
+
customHome?: string;
|
|
70
|
+
/** 默认信封包装输出模式 */
|
|
71
|
+
defaultEnvelope?: boolean;
|
|
72
|
+
/** 自定义标准输出写入函数 */
|
|
73
|
+
stdout?: (msg: string) => void;
|
|
74
|
+
/** 自定义标准错误写入函数 */
|
|
75
|
+
stderr?: (msg: string) => void;
|
|
76
|
+
/** 自定义标准输入流 */
|
|
77
|
+
stdin?: NodeJS.ReadableStream;
|
|
78
|
+
/** 自定义交互式输入提示函数(用于测试或外部调用重定向) */
|
|
79
|
+
promptInput?: (promptText: string, options?: {
|
|
80
|
+
secret?: boolean;
|
|
81
|
+
mask?: string;
|
|
82
|
+
}) => Promise<string>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 工程自省详情信息结构。
|
|
86
|
+
*/
|
|
87
|
+
export interface ProjectDetailInfo {
|
|
88
|
+
id: string;
|
|
89
|
+
name: string;
|
|
90
|
+
version: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
projectRoot: string;
|
|
93
|
+
actionsDir: string;
|
|
94
|
+
playbooksDir: string;
|
|
95
|
+
actionsCount: number;
|
|
96
|
+
playbooksCount: number;
|
|
97
|
+
actions: string[];
|
|
98
|
+
playbooks: string[];
|
|
99
|
+
configDeclared: string[];
|
|
100
|
+
configDef?: Record<string, ConfigItemDefinition>;
|
|
101
|
+
actionsMap?: Map<string, {
|
|
102
|
+
id?: string;
|
|
103
|
+
description?: string;
|
|
104
|
+
}>;
|
|
105
|
+
playbooksMap?: Map<string, any>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 聚合 Package 信息结构。
|
|
109
|
+
*/
|
|
110
|
+
export interface AggregatedPackage {
|
|
111
|
+
id: string;
|
|
112
|
+
name: string;
|
|
113
|
+
version: string;
|
|
114
|
+
description?: string;
|
|
115
|
+
path: string;
|
|
116
|
+
actionsCount: number;
|
|
117
|
+
playbooksCount: number;
|
|
118
|
+
actions: string[];
|
|
119
|
+
playbooks: string[];
|
|
120
|
+
configDeclared: string[];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 环境变量满足率检测项。
|
|
124
|
+
*/
|
|
125
|
+
export interface EnvCheckItem {
|
|
126
|
+
key: string;
|
|
127
|
+
required: boolean;
|
|
128
|
+
satisfied: boolean;
|
|
129
|
+
matchedEnv: string | null;
|
|
130
|
+
hasDefault: boolean;
|
|
131
|
+
secret: boolean;
|
|
132
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExitCode as CoreExitCode } from "@actiondock/core";
|
|
2
|
+
/**
|
|
3
|
+
* 统一退出码定义(事实源位于 core 包 StandaloneDispatcher,此处仅 re-export 维持既有导入路径兼容)。
|
|
4
|
+
* - SUCCESS: 执行成功(0)
|
|
5
|
+
* - FAILURE: 业务或框架执行失败(1)
|
|
6
|
+
* - INVALID_ARGUMENT: 命令行参数或选项错误(2)
|
|
7
|
+
* - SIGINT: 进程接收中断信号退出(130)
|
|
8
|
+
*/
|
|
9
|
+
export const ExitCode = CoreExitCode;
|
package/dist/utils/bytes.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { parseByteSize } from "
|
|
1
|
+
export { parseByteSize } from "./utils.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseByteSize } from "./utils.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseDuration } from "@actiondock/core";
|
package/dist/utils/filter.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { resolveIntent } from "
|
|
1
|
+
export { resolveIntent } from "./utils.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveIntent } from "./utils.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 子进程执行结果视图。
|
|
3
|
+
*/
|
|
4
|
+
export interface SpawnAsyncResult {
|
|
5
|
+
/** 进程退出码(null 表示被信号终止) */
|
|
6
|
+
status: number | null;
|
|
7
|
+
/** 终止信号名称 */
|
|
8
|
+
signal: string | null;
|
|
9
|
+
/** 标准输出内容 */
|
|
10
|
+
stdout: string;
|
|
11
|
+
/** 标准错误内容 */
|
|
12
|
+
stderr: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 异步执行子进程(Promise 化 spawn),保留 win32 shell 处理与退出码透传。
|
|
16
|
+
*
|
|
17
|
+
* 与 spawnSync 语义对齐:stdio 默认 pipe,进程结束(而非继承输出)后返回聚合结果。
|
|
18
|
+
*
|
|
19
|
+
* @param command 可执行文件名
|
|
20
|
+
* @param args 参数列表
|
|
21
|
+
* @param options 附加选项(cwd 与 shell 策略)
|
|
22
|
+
*/
|
|
23
|
+
export declare function spawnAsync(command: string, args: string[], options?: {
|
|
24
|
+
cwd?: string;
|
|
25
|
+
shell?: boolean;
|
|
26
|
+
stdio?: "pipe" | "inherit";
|
|
27
|
+
}): Promise<SpawnAsyncResult>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* 异步执行子进程(Promise 化 spawn),保留 win32 shell 处理与退出码透传。
|
|
4
|
+
*
|
|
5
|
+
* 与 spawnSync 语义对齐:stdio 默认 pipe,进程结束(而非继承输出)后返回聚合结果。
|
|
6
|
+
*
|
|
7
|
+
* @param command 可执行文件名
|
|
8
|
+
* @param args 参数列表
|
|
9
|
+
* @param options 附加选项(cwd 与 shell 策略)
|
|
10
|
+
*/
|
|
11
|
+
export function spawnAsync(command, args, options) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const proc = spawn(command, args, {
|
|
14
|
+
cwd: options?.cwd,
|
|
15
|
+
stdio: options?.stdio ?? "pipe",
|
|
16
|
+
shell: options?.shell ?? process.platform === "win32",
|
|
17
|
+
});
|
|
18
|
+
let stdout = "";
|
|
19
|
+
let stderr = "";
|
|
20
|
+
if (proc.stdout) {
|
|
21
|
+
proc.stdout.on("data", (chunk) => {
|
|
22
|
+
stdout += chunk.toString();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (proc.stderr) {
|
|
26
|
+
proc.stderr.on("data", (chunk) => {
|
|
27
|
+
stderr += chunk.toString();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
proc.on("error", reject);
|
|
31
|
+
proc.on("close", (status, signal) => {
|
|
32
|
+
resolve({ status, signal: signal ?? null, stdout, stderr });
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type ActionDockTarget, type ResolvedTarget } from "@actiondock/core";
|
|
2
|
+
import type { CliContext } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* 目标解析与 Target 创建所需的统一选项视图。
|
|
5
|
+
* 与既有命令内联解析逻辑保持逐字段一致,作为唯一事实源供各命令复用。
|
|
6
|
+
*/
|
|
7
|
+
export interface TargetResolutionOptions {
|
|
8
|
+
/** 显式指定的包标识或路径(对应 -P, --package) */
|
|
9
|
+
package?: string;
|
|
10
|
+
/** 远端 Profile 名称(对应 -p, --profile) */
|
|
11
|
+
profile?: string;
|
|
12
|
+
/** 远端服务地址(对应 -s, --server) */
|
|
13
|
+
server?: string;
|
|
14
|
+
/** 远端鉴权 Token(对应 -t, --token) */
|
|
15
|
+
token?: string;
|
|
16
|
+
/** 自定义数据目录(对应 --data-dir) */
|
|
17
|
+
dataDir?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 高阶目标执行辅助:统一封装「目标解析 → Target 创建 → 业务回调 → try/finally close」样板。
|
|
21
|
+
*
|
|
22
|
+
* 回调获得创建好的 target 与解析后的目标拓扑信息;无论回调成功或抛出,
|
|
23
|
+
* 都保证 target 资源被正确释放,业务异常原样透传。
|
|
24
|
+
*
|
|
25
|
+
* @param options 命令选项视图(profile/server/token/package/dataDir)
|
|
26
|
+
* @param context CLI 上下文
|
|
27
|
+
* @param fn 业务回调(target 为已创建的门面实例,resolved 为拓扑解析结果)
|
|
28
|
+
* @param localOptions 本地分支附加选项(如 scanLinkedPackages)与 localRoot 回退策略
|
|
29
|
+
*/
|
|
30
|
+
export declare function withTarget(options: TargetResolutionOptions, context: CliContext | undefined, fn: (target: ActionDockTarget, resolved: ResolvedTarget) => Promise<void>, localOptions?: {
|
|
31
|
+
/** 本地工程根目录(支持惰性工厂,仅在 local 分支求值);未提供时按 findProjectRoot 回退 */
|
|
32
|
+
localRoot?: string | (() => string | undefined);
|
|
33
|
+
/** 是否扫描全局链接包(对应 scanLinkedPackages) */
|
|
34
|
+
scanLinkedPackages?: boolean;
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* 仅远端模式目标执行辅助:创建远端 Target 并保证资源释放。
|
|
38
|
+
* 适用于 runs cancel 等明确要求远端目标的命令。
|
|
39
|
+
*/
|
|
40
|
+
export declare function withRemoteTarget(options: TargetResolutionOptions, context: CliContext | undefined, fn: (target: ActionDockTarget, resolved: ResolvedTarget) => Promise<void>): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* 目标包根目录解析(含 -P 显式寻址与当前工程回退)。
|
|
43
|
+
* 供命令在创建 Target 前统一完成包寻址,返回 null 表示当前目录无工程。
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveLocalPackageRoot(pkgId?: string): string | null;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createActionDockTarget, findProjectRoot, resolvePackageRoot, resolveTarget, } from "@actiondock/core";
|
|
2
|
+
/**
|
|
3
|
+
* 高阶目标执行辅助:统一封装「目标解析 → Target 创建 → 业务回调 → try/finally close」样板。
|
|
4
|
+
*
|
|
5
|
+
* 回调获得创建好的 target 与解析后的目标拓扑信息;无论回调成功或抛出,
|
|
6
|
+
* 都保证 target 资源被正确释放,业务异常原样透传。
|
|
7
|
+
*
|
|
8
|
+
* @param options 命令选项视图(profile/server/token/package/dataDir)
|
|
9
|
+
* @param context CLI 上下文
|
|
10
|
+
* @param fn 业务回调(target 为已创建的门面实例,resolved 为拓扑解析结果)
|
|
11
|
+
* @param localOptions 本地分支附加选项(如 scanLinkedPackages)与 localRoot 回退策略
|
|
12
|
+
*/
|
|
13
|
+
export async function withTarget(options, context, fn, localOptions) {
|
|
14
|
+
const resolved = resolveTarget({
|
|
15
|
+
profile: options.profile,
|
|
16
|
+
server: options.server,
|
|
17
|
+
token: options.token,
|
|
18
|
+
}, context?.customHome);
|
|
19
|
+
// localRoot 仅在 local 分支求值,避免远端模式下触发包寻址副作用
|
|
20
|
+
const localRoot = resolved.type === "local"
|
|
21
|
+
? (typeof localOptions?.localRoot === "function" ? localOptions.localRoot() : localOptions?.localRoot) ??
|
|
22
|
+
findProjectRoot() ??
|
|
23
|
+
undefined
|
|
24
|
+
: undefined;
|
|
25
|
+
const target = await createActionDockTarget(resolved.type === "remote"
|
|
26
|
+
? {
|
|
27
|
+
type: "remote",
|
|
28
|
+
serverUrl: resolved.serverUrl,
|
|
29
|
+
token: resolved.token,
|
|
30
|
+
}
|
|
31
|
+
: {
|
|
32
|
+
type: "local",
|
|
33
|
+
projectRoot: localRoot,
|
|
34
|
+
customHome: context?.customHome,
|
|
35
|
+
dataDir: options.dataDir || context?.dataDir,
|
|
36
|
+
...(localOptions?.scanLinkedPackages !== undefined
|
|
37
|
+
? { scanLinkedPackages: localOptions.scanLinkedPackages }
|
|
38
|
+
: undefined),
|
|
39
|
+
});
|
|
40
|
+
try {
|
|
41
|
+
await fn(target, resolved);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
await target.close();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 仅远端模式目标执行辅助:创建远端 Target 并保证资源释放。
|
|
49
|
+
* 适用于 runs cancel 等明确要求远端目标的命令。
|
|
50
|
+
*/
|
|
51
|
+
export async function withRemoteTarget(options, context, fn) {
|
|
52
|
+
const resolved = resolveTarget({
|
|
53
|
+
profile: options.profile,
|
|
54
|
+
server: options.server,
|
|
55
|
+
token: options.token,
|
|
56
|
+
}, context?.customHome);
|
|
57
|
+
const target = await createActionDockTarget({
|
|
58
|
+
type: "remote",
|
|
59
|
+
serverUrl: resolved.serverUrl,
|
|
60
|
+
token: resolved.token,
|
|
61
|
+
});
|
|
62
|
+
try {
|
|
63
|
+
await fn(target, resolved);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
await target.close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 目标包根目录解析(含 -P 显式寻址与当前工程回退)。
|
|
71
|
+
* 供命令在创建 Target 前统一完成包寻址,返回 null 表示当前目录无工程。
|
|
72
|
+
*/
|
|
73
|
+
export function resolveLocalPackageRoot(pkgId) {
|
|
74
|
+
if (pkgId) {
|
|
75
|
+
return resolvePackageRoot(pkgId);
|
|
76
|
+
}
|
|
77
|
+
return findProjectRoot();
|
|
78
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 解析意图字符串(从显式 --intent 或位置模式参数聚合)。
|
|
3
|
+
* 多个关键字使用 '|'(正则逻辑或)连接。
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolveIntent(optionsIntent?: string, positionalPatterns?: string[]): string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* 解析人类可读的字节大小字符串为整数字节数。
|
|
8
|
+
* 例如:'1mb' -> 1048576, '500kb' -> 512000, '1048576' -> 1048576
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseByteSize(str: string): number;
|
|
11
|
+
/**
|
|
12
|
+
* 将逗号分隔或多次指定的选项转换为字符串数组。
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseListOption(val: string, prev?: string[]): string[];
|
|
15
|
+
/**
|
|
16
|
+
* 根据 Package 选项或键前缀解析目标工程物理根目录。
|
|
17
|
+
*/
|
|
18
|
+
export declare function getTargetRoot(packageOption?: string, keyHint?: string): {
|
|
19
|
+
root: string;
|
|
20
|
+
key: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* 聚合命令自身选项与根程序全局选项(如 --json、--envelope、--data-dir 等)。
|
|
24
|
+
*/
|
|
25
|
+
export declare function getEffectiveOptions(rawOptions: any, cmd?: any): any;
|
|
26
|
+
/**
|
|
27
|
+
* 解析意图过滤回退策略。
|
|
28
|
+
* 机器输出模式(--json/--envelope)仅在显式传 --fallback 时回退,
|
|
29
|
+
* 人类交互模式默认回退(可被 --no-fallback 关闭)。
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveFallbackStrategy(options: {
|
|
32
|
+
fallback?: boolean;
|
|
33
|
+
json?: boolean;
|
|
34
|
+
envelope?: boolean;
|
|
35
|
+
}): {
|
|
36
|
+
isMachine: boolean;
|
|
37
|
+
shouldFallback: boolean;
|
|
38
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { resolvePackageRoot, findProjectRoot } from "@actiondock/core";
|
|
2
|
+
import { ArgumentError } from "../errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* 解析意图字符串(从显式 --intent 或位置模式参数聚合)。
|
|
5
|
+
* 多个关键字使用 '|'(正则逻辑或)连接。
|
|
6
|
+
*/
|
|
7
|
+
export function resolveIntent(optionsIntent, positionalPatterns) {
|
|
8
|
+
const parts = [];
|
|
9
|
+
if (optionsIntent && optionsIntent.trim()) {
|
|
10
|
+
parts.push(optionsIntent.trim());
|
|
11
|
+
}
|
|
12
|
+
if (positionalPatterns && positionalPatterns.length > 0) {
|
|
13
|
+
for (const p of positionalPatterns) {
|
|
14
|
+
if (typeof p === "string" && p.trim()) {
|
|
15
|
+
parts.push(p.trim());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (parts.length === 0)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (parts.length === 1)
|
|
22
|
+
return parts[0];
|
|
23
|
+
return parts.join("|");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 解析人类可读的字节大小字符串为整数字节数。
|
|
27
|
+
* 例如:'1mb' -> 1048576, '500kb' -> 512000, '1048576' -> 1048576
|
|
28
|
+
*/
|
|
29
|
+
export function parseByteSize(str) {
|
|
30
|
+
const trimmed = str.trim().toLowerCase();
|
|
31
|
+
const match = trimmed.match(/^(\d+(?:\.\d+)?)\s*([a-z]+)?$/);
|
|
32
|
+
if (!match) {
|
|
33
|
+
const num = Number(trimmed);
|
|
34
|
+
if (!isNaN(num) && num > 0)
|
|
35
|
+
return num;
|
|
36
|
+
throw new ArgumentError(`Invalid byte size format: '${str}'. Examples: '1mb', '500kb', '1048576'`);
|
|
37
|
+
}
|
|
38
|
+
const value = parseFloat(match[1]);
|
|
39
|
+
const unit = match[2] || "b";
|
|
40
|
+
switch (unit) {
|
|
41
|
+
case "b":
|
|
42
|
+
case "bytes":
|
|
43
|
+
return Math.floor(value);
|
|
44
|
+
case "k":
|
|
45
|
+
case "kb":
|
|
46
|
+
case "kib":
|
|
47
|
+
return Math.floor(value * 1024);
|
|
48
|
+
case "m":
|
|
49
|
+
case "mb":
|
|
50
|
+
case "mib":
|
|
51
|
+
return Math.floor(value * 1024 * 1024);
|
|
52
|
+
case "g":
|
|
53
|
+
case "gb":
|
|
54
|
+
case "gib":
|
|
55
|
+
return Math.floor(value * 1024 * 1024 * 1024);
|
|
56
|
+
default:
|
|
57
|
+
throw new ArgumentError(`Unsupported byte size unit '${unit}' in '${str}'`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 将逗号分隔或多次指定的选项转换为字符串数组。
|
|
62
|
+
*/
|
|
63
|
+
export function parseListOption(val, prev = []) {
|
|
64
|
+
const parts = val.split(",").map((s) => s.trim()).filter(Boolean);
|
|
65
|
+
return [...prev, ...parts];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 根据 Package 选项或键前缀解析目标工程物理根目录。
|
|
69
|
+
*/
|
|
70
|
+
export function getTargetRoot(packageOption, keyHint) {
|
|
71
|
+
let targetPackage = packageOption;
|
|
72
|
+
let effectiveKey = keyHint || "";
|
|
73
|
+
if (!targetPackage && keyHint && keyHint.includes("/")) {
|
|
74
|
+
const slashIdx = keyHint.lastIndexOf("/");
|
|
75
|
+
targetPackage = keyHint.slice(0, slashIdx);
|
|
76
|
+
effectiveKey = keyHint.slice(slashIdx + 1);
|
|
77
|
+
}
|
|
78
|
+
const root = resolvePackageRoot(targetPackage) || (targetPackage ? null : findProjectRoot());
|
|
79
|
+
if (!root) {
|
|
80
|
+
if (targetPackage) {
|
|
81
|
+
throw new ArgumentError(`Package '${targetPackage}' not found in linked packages or path`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new ArgumentError("Not in an ActionDock project (actiondock.json not found). Please specify -P, --package <id> or cd into a project directory.");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { root, key: effectiveKey };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 聚合命令自身选项与根程序全局选项(如 --json、--envelope、--data-dir 等)。
|
|
91
|
+
*/
|
|
92
|
+
export function getEffectiveOptions(rawOptions, cmd) {
|
|
93
|
+
if (cmd && typeof cmd.optsWithGlobals === "function") {
|
|
94
|
+
return { ...cmd.optsWithGlobals(), ...rawOptions };
|
|
95
|
+
}
|
|
96
|
+
return rawOptions || {};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 解析意图过滤回退策略。
|
|
100
|
+
* 机器输出模式(--json/--envelope)仅在显式传 --fallback 时回退,
|
|
101
|
+
* 人类交互模式默认回退(可被 --no-fallback 关闭)。
|
|
102
|
+
*/
|
|
103
|
+
export function resolveFallbackStrategy(options) {
|
|
104
|
+
const isMachine = Boolean(options.json || options.envelope);
|
|
105
|
+
const fallbackExplicit = options.fallback === true ||
|
|
106
|
+
(Array.isArray(process.argv) && process.argv.includes("--fallback"));
|
|
107
|
+
return {
|
|
108
|
+
isMachine,
|
|
109
|
+
shouldFallback: isMachine ? fallbackExplicit : options.fallback !== false,
|
|
110
|
+
};
|
|
111
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@actiondock/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "ActionDock CLI facade for developing, testing, building, and exporting standalone Agent Actions and Skills",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -23,25 +23,23 @@
|
|
|
23
23
|
"README.md"
|
|
24
24
|
],
|
|
25
25
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
26
|
+
"node": ">=24.12.0"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public",
|
|
30
30
|
"registry": "https://registry.npmjs.org/"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "
|
|
34
|
-
"test": "
|
|
33
|
+
"build": "node ../../scripts/build.ts",
|
|
34
|
+
"test": "node ../../scripts/run-tests.ts"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@actiondock/builder": "^2.
|
|
38
|
-
"@actiondock/core": "^2.
|
|
39
|
-
"@actiondock/mcp": "^2.
|
|
40
|
-
"@actiondock/runtime-
|
|
41
|
-
"@actiondock/
|
|
42
|
-
"
|
|
43
|
-
"commander": "^13.1.0",
|
|
44
|
-
"tsx": "^4.19.3"
|
|
37
|
+
"@actiondock/builder": "^2.2.1",
|
|
38
|
+
"@actiondock/core": "^2.2.1",
|
|
39
|
+
"@actiondock/mcp": "^2.2.1",
|
|
40
|
+
"@actiondock/runtime-node": "^2.2.1",
|
|
41
|
+
"@actiondock/sdk": "^2.2.1",
|
|
42
|
+
"commander": "^13.1.0"
|
|
45
43
|
},
|
|
46
44
|
"devDependencies": {
|
|
47
45
|
"typescript": "^5.7.0"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Command } from "commander";
|
|
2
|
-
import { executeAction } from "@actiondock/runtime-cli";
|
|
3
|
-
export { executeAction };
|
|
4
|
-
export { registerActionCreateCommand } from "./create";
|
|
5
|
-
export { registerActionSyncCommand } from "./sync";
|
|
6
|
-
export { registerActionListCommand } from "./list";
|
|
7
|
-
export { registerActionShowCommand } from "./show";
|
|
8
|
-
export { registerActionValidateCommand } from "./validate";
|
|
9
|
-
export { registerActionRunCommand } from "./run";
|
|
10
|
-
/**
|
|
11
|
-
* 注册 Action 相关的 CLI 命令集合。
|
|
12
|
-
* 委托 list, show, validate, run 至 @actiondock/runtime-cli,保留开发者专用的 create 与 sync 命令。
|
|
13
|
-
*
|
|
14
|
-
* @param program Commander 根程序对象
|
|
15
|
-
*/
|
|
16
|
-
export declare function registerActionCommands(program: Command): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./action/index";
|