@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
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { checkGeneratedTypes, findProjectRoot, GENERATED_TYPES_OUTDATED_CODE, loadActions, loadProjectConfig, resolvePackageRoot, } from "@actiondock/core";
|
|
2
|
+
import { ArgumentError, ExecutionError } from "../errors.js";
|
|
3
|
+
import { renderActionValidation, renderResult } from "../renderer.js";
|
|
4
|
+
import { getEffectiveOptions } from "../utils/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* 注册顶层统一 validate 命令:校验 Action 的 Schema 与方法定义完整性。
|
|
7
|
+
*
|
|
8
|
+
* @param program Commander 根程序对象
|
|
9
|
+
* @param context 命令行上下文
|
|
10
|
+
*/
|
|
11
|
+
export function registerValidateCommand(program, context) {
|
|
12
|
+
program
|
|
13
|
+
.command("validate [id]")
|
|
14
|
+
.description("Validate action schemas and definitions")
|
|
15
|
+
.option("-P, --package <id>", "Target package ID or path")
|
|
16
|
+
.option("--json", "Output as JSON")
|
|
17
|
+
.option("--envelope", "Wrap JSON output in standard envelope")
|
|
18
|
+
.option("--data-dir <path>", "Custom database storage directory")
|
|
19
|
+
.action(async (id, rawOptions, cmd) => {
|
|
20
|
+
const options = getEffectiveOptions(rawOptions, cmd);
|
|
21
|
+
let root = null;
|
|
22
|
+
if (options.package) {
|
|
23
|
+
root = resolvePackageRoot(options.package);
|
|
24
|
+
if (!root) {
|
|
25
|
+
throw new ArgumentError(`Package '${options.package}' not found in linked packages or path`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
root = findProjectRoot();
|
|
30
|
+
}
|
|
31
|
+
if (!root) {
|
|
32
|
+
throw new ArgumentError("Not in an ActionDock project (actiondock.json not found).\nPlease specify -P, --package <id> or cd into a project directory.");
|
|
33
|
+
}
|
|
34
|
+
const config = loadProjectConfig(root);
|
|
35
|
+
const actions = await loadActions(root, config.actionsDir);
|
|
36
|
+
let toValidate = [];
|
|
37
|
+
if (id) {
|
|
38
|
+
const act = actions.get(id);
|
|
39
|
+
if (!act) {
|
|
40
|
+
throw new ArgumentError(`Action '${id}' not found in project '${config.id}'`);
|
|
41
|
+
}
|
|
42
|
+
toValidate = [{ id, act, spec: config.actions?.[id] }];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
toValidate = Array.from(actions.entries()).map(([actId, act]) => ({
|
|
46
|
+
id: actId,
|
|
47
|
+
act,
|
|
48
|
+
spec: config.actions?.[actId],
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
const results = [];
|
|
52
|
+
for (const item of toValidate) {
|
|
53
|
+
const errors = [];
|
|
54
|
+
if (!item.id)
|
|
55
|
+
errors.push("Missing id property");
|
|
56
|
+
if (!item.act?.run || typeof item.act.run !== "function")
|
|
57
|
+
errors.push("Missing run method");
|
|
58
|
+
const inSchema = item.spec?.inputSchema ?? item.act.inputSchema;
|
|
59
|
+
if (inSchema && typeof inSchema !== "object") {
|
|
60
|
+
errors.push("Invalid inputSchema object");
|
|
61
|
+
}
|
|
62
|
+
const outSchema = item.spec?.outputSchema ?? item.act.outputSchema;
|
|
63
|
+
if (outSchema && typeof outSchema !== "object") {
|
|
64
|
+
errors.push("Invalid outputSchema object");
|
|
65
|
+
}
|
|
66
|
+
results.push({
|
|
67
|
+
id: item.id,
|
|
68
|
+
valid: errors.length === 0,
|
|
69
|
+
errors,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const allValid = results.every((r) => r.valid);
|
|
73
|
+
const validationPayload = { valid: allValid, results };
|
|
74
|
+
renderResult(validationPayload, {
|
|
75
|
+
json: options.json,
|
|
76
|
+
envelope: options.envelope,
|
|
77
|
+
humanFormatter: () => renderActionValidation(results),
|
|
78
|
+
context,
|
|
79
|
+
});
|
|
80
|
+
if (!allValid) {
|
|
81
|
+
process.exitCode = 1;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// 校验 Action 本地相对依赖完整性
|
|
85
|
+
try {
|
|
86
|
+
const { SelectionPlanner } = await import("@actiondock/builder");
|
|
87
|
+
SelectionPlanner.plan({ projectRoot: root, actions: id ? [id] : undefined });
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
if (err?.code === "UNMET_LOCAL_DEPENDENCY" ||
|
|
91
|
+
err?.code === "EXTERNAL_LOCAL_DEPENDENCY" ||
|
|
92
|
+
err?.code === "FILE_NOT_FOUND") {
|
|
93
|
+
throw new ExecutionError(`Action dependency integrity validation failed:\n${err.message}`, undefined, err.code);
|
|
94
|
+
}
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
// 只读校验已生成的类型文件摘要是否过期
|
|
98
|
+
const typeCheck = checkGeneratedTypes(root);
|
|
99
|
+
if (typeCheck.exists && typeCheck.outdated) {
|
|
100
|
+
throw new ExecutionError(`Generated types in ${typeCheck.filePath} are outdated. Expected manifest digest '${typeCheck.expectedDigest}', but got '${typeCheck.actualDigest || "none"}'. Run 'ad generate types' to update.`, {
|
|
101
|
+
expectedDigest: typeCheck.expectedDigest,
|
|
102
|
+
actualDigest: typeCheck.actualDigest,
|
|
103
|
+
}, GENERATED_TYPES_OUTDATED_CODE);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ExitCodeValue } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* 命令行标准错误基类。
|
|
4
|
+
*/
|
|
5
|
+
export declare class CliError extends Error {
|
|
6
|
+
readonly exitCode: ExitCodeValue;
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly details?: unknown;
|
|
9
|
+
constructor(message: string, exitCode?: ExitCodeValue, code?: string, details?: unknown);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 命令行参数与选项校验错误(退出码为 2)。
|
|
13
|
+
*/
|
|
14
|
+
export declare class ArgumentError extends CliError {
|
|
15
|
+
constructor(message: string, details?: unknown);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 业务逻辑或框架执行失败错误(退出码为 1)。
|
|
19
|
+
*/
|
|
20
|
+
export declare class ExecutionError extends CliError {
|
|
21
|
+
constructor(message: string, details?: unknown, code?: string);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 用户中断信号错误(退出码为 130)。
|
|
25
|
+
*/
|
|
26
|
+
export declare class SigintError extends CliError {
|
|
27
|
+
constructor(message?: string);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 标准化错误信息解析结果。
|
|
31
|
+
*/
|
|
32
|
+
export interface FormattedError {
|
|
33
|
+
code: string;
|
|
34
|
+
message: string;
|
|
35
|
+
exitCode: ExitCodeValue;
|
|
36
|
+
details?: unknown;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 解析并格式化任意异常为结构化错误对象。
|
|
40
|
+
*
|
|
41
|
+
* @param err 待解析的异常对象
|
|
42
|
+
*/
|
|
43
|
+
export declare function formatError(err: unknown): FormattedError;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ExitCode } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* CLI 信封错误码常量(仅 CLI 输出协议使用,属包内部码,就地常量化管理)。
|
|
4
|
+
*/
|
|
5
|
+
const CLI_CODE_SUCCESS = "SUCCESS";
|
|
6
|
+
const CLI_CODE_INVALID_ARGUMENT = "INVALID_ARGUMENT";
|
|
7
|
+
const CLI_CODE_ERROR = "ERROR";
|
|
8
|
+
const CLI_CODE_UNKNOWN_ERROR = "UNKNOWN_ERROR";
|
|
9
|
+
/**
|
|
10
|
+
* 命令行标准错误基类。
|
|
11
|
+
*/
|
|
12
|
+
export class CliError extends Error {
|
|
13
|
+
exitCode;
|
|
14
|
+
code;
|
|
15
|
+
details;
|
|
16
|
+
constructor(message, exitCode = ExitCode.FAILURE, code = "CLI_ERROR", details) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "CliError";
|
|
19
|
+
this.exitCode = exitCode;
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.details = details;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 命令行参数与选项校验错误(退出码为 2)。
|
|
26
|
+
*/
|
|
27
|
+
export class ArgumentError extends CliError {
|
|
28
|
+
constructor(message, details) {
|
|
29
|
+
super(message, ExitCode.INVALID_ARGUMENT, "INVALID_ARGUMENT", details);
|
|
30
|
+
this.name = "ArgumentError";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 业务逻辑或框架执行失败错误(退出码为 1)。
|
|
35
|
+
*/
|
|
36
|
+
export class ExecutionError extends CliError {
|
|
37
|
+
constructor(message, details, code = "EXECUTION_FAILURE") {
|
|
38
|
+
super(message, ExitCode.FAILURE, code, details);
|
|
39
|
+
this.name = "ExecutionError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 用户中断信号错误(退出码为 130)。
|
|
44
|
+
*/
|
|
45
|
+
export class SigintError extends CliError {
|
|
46
|
+
constructor(message = "Interrupted by SIGINT") {
|
|
47
|
+
super(message, ExitCode.SIGINT, "SIGINT_INTERRUPTED");
|
|
48
|
+
this.name = "SigintError";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 解析并格式化任意异常为结构化错误对象。
|
|
53
|
+
*
|
|
54
|
+
* @param err 待解析的异常对象
|
|
55
|
+
*/
|
|
56
|
+
export function formatError(err) {
|
|
57
|
+
if (err instanceof CliError) {
|
|
58
|
+
return {
|
|
59
|
+
code: err.code,
|
|
60
|
+
message: err.message,
|
|
61
|
+
exitCode: err.exitCode,
|
|
62
|
+
details: err.details,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Commander.js 原生错误处理
|
|
66
|
+
if (typeof err === "object" && err !== null && "code" in err && typeof err.code === "string") {
|
|
67
|
+
const commanderErr = err;
|
|
68
|
+
const code = commanderErr.code;
|
|
69
|
+
// 参数类异常
|
|
70
|
+
if (code.startsWith("commander.unknownOption") ||
|
|
71
|
+
code.startsWith("commander.missingArgument") ||
|
|
72
|
+
code.startsWith("commander.missingMandatoryOptionValue") ||
|
|
73
|
+
code.startsWith("commander.optionMissingArgument") ||
|
|
74
|
+
code.startsWith("commander.invalidArgument") ||
|
|
75
|
+
code.startsWith("commander.excessArguments")) {
|
|
76
|
+
return {
|
|
77
|
+
code: CLI_CODE_INVALID_ARGUMENT,
|
|
78
|
+
message: commanderErr.message,
|
|
79
|
+
exitCode: ExitCode.INVALID_ARGUMENT,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// 正常退出(如 --help 或 --version)
|
|
83
|
+
if (code === "commander.helpDisplayed" || code === "commander.version") {
|
|
84
|
+
return {
|
|
85
|
+
code: CLI_CODE_SUCCESS,
|
|
86
|
+
message: commanderErr.message,
|
|
87
|
+
exitCode: ExitCode.SUCCESS,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (err instanceof Error) {
|
|
92
|
+
return {
|
|
93
|
+
code: CLI_CODE_ERROR,
|
|
94
|
+
message: err.message,
|
|
95
|
+
exitCode: ExitCode.FAILURE,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
code: CLI_CODE_UNKNOWN_ERROR,
|
|
100
|
+
message: String(err),
|
|
101
|
+
exitCode: ExitCode.FAILURE,
|
|
102
|
+
};
|
|
103
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./renderer.js";
|
|
4
|
+
export * from "./prompt.js";
|
|
5
|
+
export * from "./standalone/index.js";
|
|
6
|
+
export * from "./utils/index.js";
|
|
7
|
+
export * from "./services/index.js";
|
|
8
|
+
export * from "./commands/index.js";
|
|
2
9
|
/**
|
|
3
10
|
* ActionDock CLI 主执行入口函数。
|
|
4
11
|
*
|