@actiondock/core 2.0.11 → 2.2.0
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 +61 -30
- package/dist/app/app.d.ts +73 -0
- package/dist/app/app.js +700 -0
- package/dist/app/index.d.ts +2 -0
- package/dist/app/index.js +2 -0
- package/dist/app/types.d.ts +283 -0
- package/dist/app/types.js +1 -0
- package/dist/catalog/action-index.d.ts +9 -0
- package/dist/catalog/action-index.js +93 -0
- package/dist/catalog/action-resolver.d.ts +20 -0
- package/dist/catalog/action-resolver.js +95 -0
- package/dist/catalog/index.d.ts +5 -0
- package/dist/catalog/index.js +5 -0
- package/dist/catalog/location-registry.d.ts +15 -0
- package/dist/catalog/location-registry.js +138 -0
- package/dist/catalog/package-catalog.d.ts +7 -0
- package/dist/catalog/package-catalog.js +76 -0
- package/dist/catalog/types.d.ts +68 -0
- package/dist/catalog/types.js +1 -0
- package/dist/doctor/doctor.d.ts +7 -0
- package/dist/doctor/doctor.js +613 -0
- package/dist/doctor/index.d.ts +2 -0
- package/dist/doctor/index.js +2 -0
- package/dist/doctor/types.d.ts +23 -0
- package/dist/doctor/types.js +1 -0
- package/dist/errors.d.ts +122 -0
- package/dist/errors.js +123 -0
- package/dist/execution/index.d.ts +2 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/service.d.ts +79 -0
- package/dist/execution/service.js +633 -0
- package/dist/execution/types.d.ts +131 -0
- package/dist/execution/types.js +1 -0
- package/dist/export/index.d.ts +1 -0
- package/dist/export/index.js +1 -0
- package/dist/export/templates.d.ts +71 -0
- package/dist/export/templates.js +621 -0
- package/dist/filter/index.d.ts +1 -0
- package/dist/filter/index.js +1 -0
- package/dist/filter/intent.d.ts +33 -0
- package/dist/filter/intent.js +123 -0
- package/dist/host/host.d.ts +55 -0
- package/dist/host/host.js +740 -0
- package/dist/host/index.d.ts +2 -0
- package/dist/host/index.js +2 -0
- package/dist/host/types.d.ts +81 -0
- package/dist/host/types.js +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +20 -0
- package/dist/ipc/diagnostic.d.ts +65 -0
- package/dist/ipc/diagnostic.js +129 -0
- package/dist/ipc/host.d.ts +7 -0
- package/dist/ipc/host.js +93 -0
- package/dist/ipc/index.d.ts +4 -0
- package/dist/ipc/index.js +4 -0
- package/dist/ipc/target.d.ts +56 -0
- package/dist/ipc/target.js +297 -0
- package/dist/ipc/types.d.ts +42 -0
- package/dist/ipc/types.js +1 -0
- package/dist/platform/default.d.ts +32 -0
- package/dist/platform/default.js +40 -0
- package/dist/platform/index.d.ts +3 -0
- package/dist/platform/index.js +3 -0
- package/dist/platform/node-fs.d.ts +37 -0
- package/dist/platform/node-fs.js +81 -0
- package/dist/platform/types.d.ts +104 -0
- package/dist/platform/types.js +1 -0
- package/dist/profile/client.d.ts +162 -0
- package/dist/profile/client.js +467 -0
- package/dist/profile/index.d.ts +3 -0
- package/dist/profile/index.js +3 -0
- package/dist/profile/manager.d.ts +47 -0
- package/dist/profile/manager.js +294 -0
- package/dist/profile/types.d.ts +61 -0
- package/dist/profile/types.js +1 -0
- package/dist/project/closure.d.ts +25 -0
- package/dist/project/closure.js +68 -0
- package/dist/project/digest.d.ts +29 -0
- package/dist/project/digest.js +324 -0
- package/dist/project/index.d.ts +10 -0
- package/dist/project/index.js +10 -0
- package/dist/project/init.d.ts +26 -0
- package/dist/project/init.js +175 -0
- package/dist/project/loader.d.ts +99 -0
- package/dist/project/loader.js +484 -0
- package/dist/project/lockfile.d.ts +55 -0
- package/dist/project/lockfile.js +175 -0
- package/dist/project/manifest.d.ts +22 -0
- package/dist/project/manifest.js +220 -0
- package/dist/project/resolver.d.ts +116 -0
- package/dist/project/resolver.js +376 -0
- package/dist/project/transactions.d.ts +103 -0
- package/dist/project/transactions.js +1203 -0
- package/dist/project/types-generator.d.ts +33 -0
- package/dist/project/types-generator.js +168 -0
- package/dist/project/types.d.ts +107 -0
- package/dist/project/types.js +1 -0
- package/dist/registry/index.d.ts +5 -0
- package/dist/registry/index.js +5 -0
- package/dist/registry/lock.d.ts +27 -0
- package/dist/registry/lock.js +93 -0
- package/dist/registry/registry.d.ts +45 -0
- package/dist/registry/registry.js +611 -0
- package/dist/registry/resolve.d.ts +62 -0
- package/dist/registry/resolve.js +195 -0
- package/dist/registry/scan.d.ts +38 -0
- package/dist/registry/scan.js +135 -0
- package/dist/registry/types.d.ts +117 -0
- package/dist/registry/types.js +1 -0
- package/dist/runtime/action-collection.d.ts +27 -0
- package/dist/runtime/action-collection.js +57 -0
- package/dist/runtime/clock.d.ts +19 -0
- package/dist/runtime/clock.js +17 -0
- package/dist/runtime/context.d.ts +86 -0
- package/dist/runtime/context.js +242 -0
- package/dist/runtime/env.d.ts +56 -0
- package/dist/runtime/env.js +159 -0
- package/dist/runtime/events.d.ts +93 -0
- package/dist/runtime/events.js +604 -0
- package/dist/runtime/execution-manager.d.ts +48 -0
- package/dist/runtime/execution-manager.js +66 -0
- package/dist/runtime/index.d.ts +10 -0
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/module-loader.d.ts +34 -0
- package/dist/runtime/module-loader.js +16 -0
- package/dist/runtime/process.d.ts +9 -0
- package/dist/runtime/process.js +146 -0
- package/dist/runtime/runner.d.ts +293 -0
- package/dist/runtime/runner.js +984 -0
- package/dist/runtime/standalone.d.ts +89 -0
- package/dist/runtime/standalone.js +536 -0
- package/dist/schema/validator.d.ts +28 -0
- package/dist/schema/validator.js +116 -0
- package/dist/server/body.d.ts +40 -0
- package/dist/server/body.js +93 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +5 -0
- package/dist/server/routes/actions.d.ts +5 -0
- package/dist/server/routes/actions.js +298 -0
- package/dist/server/routes/common.d.ts +47 -0
- package/dist/server/routes/common.js +104 -0
- package/dist/server/routes/config.d.ts +6 -0
- package/dist/server/routes/config.js +173 -0
- package/dist/server/routes/doctor.d.ts +5 -0
- package/dist/server/routes/doctor.js +63 -0
- package/dist/server/routes/health.d.ts +5 -0
- package/dist/server/routes/health.js +35 -0
- package/dist/server/routes/index.d.ts +9 -0
- package/dist/server/routes/index.js +9 -0
- package/dist/server/routes/info.d.ts +7 -0
- package/dist/server/routes/info.js +158 -0
- package/dist/server/routes/playbooks.d.ts +5 -0
- package/dist/server/routes/playbooks.js +134 -0
- package/dist/server/routes/runs.d.ts +5 -0
- package/dist/server/routes/runs.js +343 -0
- package/dist/server/routes/state.d.ts +6 -0
- package/dist/server/routes/state.js +169 -0
- package/dist/server/security.d.ts +44 -0
- package/dist/server/security.js +101 -0
- package/dist/server/server.d.ts +15 -0
- package/dist/server/server.js +355 -0
- package/dist/server/types.d.ts +78 -0
- package/dist/server/types.js +1 -0
- package/dist/storage/data-dir-lock.d.ts +119 -0
- package/dist/storage/data-dir-lock.js +1016 -0
- package/dist/storage/driver.d.ts +9 -0
- package/dist/storage/driver.js +59 -0
- package/dist/storage/index.d.ts +64 -0
- package/dist/storage/index.js +98 -0
- package/dist/storage/lazy.d.ts +8 -0
- package/dist/storage/lazy.js +44 -0
- package/dist/storage/mask.d.ts +26 -0
- package/dist/storage/mask.js +48 -0
- package/dist/storage/params.d.ts +13 -0
- package/dist/storage/params.js +32 -0
- package/dist/storage/sqlite.d.ts +79 -0
- package/dist/storage/sqlite.js +689 -0
- package/dist/storage/types.d.ts +172 -0
- package/dist/storage/types.js +14 -0
- package/dist/target/index.d.ts +4 -0
- package/dist/target/index.js +4 -0
- package/dist/target/local.d.ts +52 -0
- package/dist/target/local.js +343 -0
- package/dist/target/remote.d.ts +76 -0
- package/dist/target/remote.js +839 -0
- package/dist/target/target.d.ts +6 -0
- package/dist/target/target.js +35 -0
- package/dist/target/types.d.ts +246 -0
- package/dist/target/types.js +34 -0
- package/dist/utils/index.d.ts +49 -0
- package/dist/utils/index.js +180 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +4 -0
- package/package.json +13 -13
- package/src/build/index.ts +0 -1
- package/src/build/templates.ts +0 -59
- package/src/catalog/action-index.ts +0 -92
- package/src/catalog/action-resolver.ts +0 -120
- package/src/catalog/index.ts +0 -5
- package/src/catalog/location-registry.ts +0 -134
- package/src/catalog/package-catalog.ts +0 -87
- package/src/catalog/types.ts +0 -75
- package/src/doctor/doctor.ts +0 -419
- package/src/doctor/index.ts +0 -2
- package/src/doctor/types.ts +0 -25
- package/src/execution/index.ts +0 -2
- package/src/execution/service.ts +0 -322
- package/src/execution/types.ts +0 -73
- package/src/export/index.ts +0 -1
- package/src/export/templates.ts +0 -590
- package/src/filter/index.ts +0 -1
- package/src/filter/intent.ts +0 -154
- package/src/index.ts +0 -16
- package/src/profile/client.ts +0 -552
- package/src/profile/index.ts +0 -3
- package/src/profile/manager.ts +0 -341
- package/src/profile/types.ts +0 -71
- package/src/project/index.ts +0 -4
- package/src/project/init.ts +0 -242
- package/src/project/loader.ts +0 -479
- package/src/project/manifest.ts +0 -299
- package/src/project/types.ts +0 -141
- package/src/registry/index.ts +0 -2
- package/src/registry/registry.ts +0 -940
- package/src/registry/types.ts +0 -127
- package/src/runtime/clock.ts +0 -41
- package/src/runtime/context.ts +0 -259
- package/src/runtime/env.ts +0 -172
- package/src/runtime/events.ts +0 -142
- package/src/runtime/execution-manager.ts +0 -74
- package/src/runtime/index.ts +0 -10
- package/src/runtime/module-loader.ts +0 -67
- package/src/runtime/process.ts +0 -245
- package/src/runtime/runner.ts +0 -527
- package/src/runtime/standalone.ts +0 -429
- package/src/schema/validator.ts +0 -61
- package/src/server/body.ts +0 -112
- package/src/server/index.ts +0 -7
- package/src/server/routes/actions.ts +0 -262
- package/src/server/routes/common.ts +0 -126
- package/src/server/routes/config.ts +0 -147
- package/src/server/routes/doctor.ts +0 -29
- package/src/server/routes/health.ts +0 -40
- package/src/server/routes/index.ts +0 -9
- package/src/server/routes/info.ts +0 -221
- package/src/server/routes/playbooks.ts +0 -109
- package/src/server/routes/runs.ts +0 -301
- package/src/server/routes/state.ts +0 -133
- package/src/server/runtime-registry.ts +0 -115
- package/src/server/security.ts +0 -115
- package/src/server/server.ts +0 -251
- package/src/server/types.ts +0 -57
- package/src/storage/driver.ts +0 -126
- package/src/storage/index.ts +0 -81
- package/src/storage/mask.ts +0 -34
- package/src/storage/sqlite.ts +0 -714
- package/src/storage/types.ts +0 -139
- package/src/utils/index.ts +0 -62
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 内存中活跃执行句柄(In-flight Execution Handles)生命周期管理器。
|
|
3
|
+
*
|
|
4
|
+
* 职责:
|
|
5
|
+
* 1. 集中追踪正在执行的异步 Action 任务句柄。
|
|
6
|
+
* 2. 任务完成(无论成功或失败)后通过 Promise.finally 自动注销,防止内存泄漏。
|
|
7
|
+
* 3. 支持依据 runId 查询、遍历或主动发送取消信号(cancel)。
|
|
8
|
+
*/
|
|
9
|
+
export class ExecutionManager {
|
|
10
|
+
active = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* 注册一个活跃的执行句柄。
|
|
13
|
+
* 当底层 Promise 完成结算(resolve/reject)时,自动从活跃映射表中移除。
|
|
14
|
+
*
|
|
15
|
+
* @param handle 执行句柄对象
|
|
16
|
+
*/
|
|
17
|
+
register(handle) {
|
|
18
|
+
this.active.set(handle.runId, handle);
|
|
19
|
+
handle.result.finally(() => {
|
|
20
|
+
this.active.delete(handle.runId);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 根据 runId 检索正在执行的任务句柄。
|
|
25
|
+
*
|
|
26
|
+
* @param runId 运行 ID
|
|
27
|
+
* @returns 匹配的 ExecutionHandle 或 undefined
|
|
28
|
+
*/
|
|
29
|
+
get(runId) {
|
|
30
|
+
return this.active.get(runId);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 向指定 runId 的在途执行任务发送取消信号。
|
|
34
|
+
*
|
|
35
|
+
* @param runId 目标运行 ID
|
|
36
|
+
* @param reason 取消原因描述
|
|
37
|
+
* @returns 若句柄存在且成功触发中断返回 true;若任务不存在或已完成返回 false
|
|
38
|
+
*/
|
|
39
|
+
cancel(runId, reason) {
|
|
40
|
+
const handle = this.active.get(runId);
|
|
41
|
+
if (!handle) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return handle.cancel(reason);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 手动从活跃集合中移除执行句柄。
|
|
48
|
+
*
|
|
49
|
+
* @param runId 运行 ID
|
|
50
|
+
*/
|
|
51
|
+
remove(runId) {
|
|
52
|
+
this.active.delete(runId);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 获取当前系统中所有正在执行的活跃句柄列表。
|
|
56
|
+
*/
|
|
57
|
+
list() {
|
|
58
|
+
return Array.from(this.active.values());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 清空所有活跃执行句柄。
|
|
62
|
+
*/
|
|
63
|
+
clear() {
|
|
64
|
+
this.active.clear();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./context.js";
|
|
2
|
+
export * from "./action-collection.js";
|
|
3
|
+
export * from "./runner.js";
|
|
4
|
+
export * from "./execution-manager.js";
|
|
5
|
+
export * from "./standalone.js";
|
|
6
|
+
export * from "./env.js";
|
|
7
|
+
export * from "./clock.js";
|
|
8
|
+
export * from "./process.js";
|
|
9
|
+
export * from "./events.js";
|
|
10
|
+
export * from "./module-loader.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./context.js";
|
|
2
|
+
export * from "./action-collection.js";
|
|
3
|
+
export * from "./runner.js";
|
|
4
|
+
export * from "./execution-manager.js";
|
|
5
|
+
export * from "./standalone.js";
|
|
6
|
+
export * from "./env.js";
|
|
7
|
+
export * from "./clock.js";
|
|
8
|
+
export * from "./process.js";
|
|
9
|
+
export * from "./events.js";
|
|
10
|
+
export * from "./module-loader.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一源码模块加载器接口。
|
|
3
|
+
* 解耦 Action 与各类扩展模块的具体加载机制(如 ECMAScript 原生 import、tsx 动态转译加载等)。
|
|
4
|
+
*/
|
|
5
|
+
export interface ModuleLoader {
|
|
6
|
+
/**
|
|
7
|
+
* 解析模块标识符为绝对路径或完整 URL。
|
|
8
|
+
*
|
|
9
|
+
* @param specifier 模块规范说明符或物理路径
|
|
10
|
+
* @param parentPath 发起解析的父级文件或目录路径
|
|
11
|
+
*/
|
|
12
|
+
resolve?(specifier: string, parentPath?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* 动态加载模块并返回命名空间全量导出对象。
|
|
15
|
+
*
|
|
16
|
+
* @param specifier 模块规范说明符或物理路径
|
|
17
|
+
* @param parentPath 发起加载的父级文件或目录路径
|
|
18
|
+
*/
|
|
19
|
+
load<T = any>(specifier: string, parentPath?: string): Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* 加载模块并解包其默认导出(default 或 action 属性)。
|
|
22
|
+
*
|
|
23
|
+
* @param specifier 模块规范说明符或物理路径
|
|
24
|
+
* @param parentPath 发起加载的父级文件或目录路径
|
|
25
|
+
*/
|
|
26
|
+
loadDefault?<T = any>(specifier: string, parentPath?: string): Promise<T>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 基于标准 ECMAScript 动态 import 的默认模块加载器。
|
|
30
|
+
*/
|
|
31
|
+
export declare class DefaultModuleLoader implements ModuleLoader {
|
|
32
|
+
load<T = any>(specifier: string, _parentPath?: string): Promise<T>;
|
|
33
|
+
loadDefault<T = any>(specifier: string, parentPath?: string): Promise<T>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
2
|
+
/**
|
|
3
|
+
* 基于标准 ECMAScript 动态 import 的默认模块加载器。
|
|
4
|
+
*/
|
|
5
|
+
export class DefaultModuleLoader {
|
|
6
|
+
async load(specifier, _parentPath) {
|
|
7
|
+
const importSpecifier = specifier.startsWith("file://")
|
|
8
|
+
? specifier
|
|
9
|
+
: pathToFileURL(specifier).href;
|
|
10
|
+
return (await import(importSpecifier));
|
|
11
|
+
}
|
|
12
|
+
async loadDefault(specifier, parentPath) {
|
|
13
|
+
const mod = await this.load(specifier, parentPath);
|
|
14
|
+
return (mod?.default !== undefined ? mod.default : mod?.action !== undefined ? mod.action : mod);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ProcessAPI, ProcessExecOptions, ProcessResult } from "@actiondock/sdk";
|
|
2
|
+
export type ProcessExecutor = ProcessAPI;
|
|
3
|
+
/**
|
|
4
|
+
* 基于 Node.js 标准 child_process 实现的基础进程执行器。
|
|
5
|
+
*/
|
|
6
|
+
export declare class DefaultProcessExecutor implements ProcessExecutor {
|
|
7
|
+
exec(command: string, args?: string[], options?: ProcessExecOptions): Promise<ProcessResult>;
|
|
8
|
+
spawn(command: string, args?: string[], options?: ProcessExecOptions): Promise<ProcessResult>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { PROCESS_OUTPUT_LIMIT, PROCESS_SPAWN_ERROR } from "../errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* 基于 Node.js 标准 child_process 实现的基础进程执行器。
|
|
5
|
+
*/
|
|
6
|
+
export class DefaultProcessExecutor {
|
|
7
|
+
async exec(command, args = [], options = {}) {
|
|
8
|
+
const startTime = Date.now();
|
|
9
|
+
const maxOutputBytes = options.maxOutputBytes ?? 10 * 1024 * 1024;
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
let stdoutBuf = "";
|
|
12
|
+
let stderrBuf = "";
|
|
13
|
+
let totalBytes = 0;
|
|
14
|
+
let timedOut = false;
|
|
15
|
+
let cancelled = false;
|
|
16
|
+
let error;
|
|
17
|
+
const cp = spawn(command, args, {
|
|
18
|
+
cwd: options.cwd,
|
|
19
|
+
env: options.env ? { ...process.env, ...options.env } : process.env,
|
|
20
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
21
|
+
});
|
|
22
|
+
if (options.input) {
|
|
23
|
+
cp.stdin.write(options.input);
|
|
24
|
+
cp.stdin.end();
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
cp.stdin.end();
|
|
28
|
+
}
|
|
29
|
+
let timer;
|
|
30
|
+
let forceKillTimer;
|
|
31
|
+
if (options.timeoutMs && options.timeoutMs > 0) {
|
|
32
|
+
timer = setTimeout(() => {
|
|
33
|
+
timedOut = true;
|
|
34
|
+
cp.kill("SIGTERM");
|
|
35
|
+
forceKillTimer = setTimeout(() => {
|
|
36
|
+
if (!cp.killed)
|
|
37
|
+
cp.kill("SIGKILL");
|
|
38
|
+
}, 1000);
|
|
39
|
+
}, options.timeoutMs);
|
|
40
|
+
}
|
|
41
|
+
const onAbort = () => {
|
|
42
|
+
cancelled = true;
|
|
43
|
+
cp.kill("SIGTERM");
|
|
44
|
+
forceKillTimer = setTimeout(() => {
|
|
45
|
+
if (!cp.killed)
|
|
46
|
+
cp.kill("SIGKILL");
|
|
47
|
+
}, 1000);
|
|
48
|
+
};
|
|
49
|
+
if (options.signal) {
|
|
50
|
+
if (options.signal.aborted) {
|
|
51
|
+
onAbort();
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const cleanup = () => {
|
|
58
|
+
if (timer) {
|
|
59
|
+
clearTimeout(timer);
|
|
60
|
+
timer = undefined;
|
|
61
|
+
}
|
|
62
|
+
if (forceKillTimer) {
|
|
63
|
+
clearTimeout(forceKillTimer);
|
|
64
|
+
forceKillTimer = undefined;
|
|
65
|
+
}
|
|
66
|
+
if (options.signal) {
|
|
67
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
cp.stdout?.on("data", (chunk) => {
|
|
71
|
+
totalBytes += chunk.length;
|
|
72
|
+
if (totalBytes > maxOutputBytes) {
|
|
73
|
+
error = {
|
|
74
|
+
code: PROCESS_OUTPUT_LIMIT,
|
|
75
|
+
message: `Process output exceeded limit of ${maxOutputBytes} bytes`,
|
|
76
|
+
};
|
|
77
|
+
cp.kill("SIGKILL");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
stdoutBuf += chunk.toString("utf-8");
|
|
81
|
+
});
|
|
82
|
+
cp.stderr?.on("data", (chunk) => {
|
|
83
|
+
totalBytes += chunk.length;
|
|
84
|
+
if (totalBytes > maxOutputBytes) {
|
|
85
|
+
error = {
|
|
86
|
+
code: PROCESS_OUTPUT_LIMIT,
|
|
87
|
+
message: `Process output exceeded limit of ${maxOutputBytes} bytes`,
|
|
88
|
+
};
|
|
89
|
+
cp.kill("SIGKILL");
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
stderrBuf += chunk.toString("utf-8");
|
|
93
|
+
});
|
|
94
|
+
cp.on("error", (err) => {
|
|
95
|
+
cleanup();
|
|
96
|
+
const durationMs = Date.now() - startTime;
|
|
97
|
+
const res = {
|
|
98
|
+
ok: false,
|
|
99
|
+
exitCode: null,
|
|
100
|
+
stdout: stdoutBuf.trim(),
|
|
101
|
+
stderr: stderrBuf.trim() || err.message,
|
|
102
|
+
raw: new TextEncoder().encode(stdoutBuf),
|
|
103
|
+
timedOut,
|
|
104
|
+
cancelled,
|
|
105
|
+
durationMs,
|
|
106
|
+
error: error || {
|
|
107
|
+
code: PROCESS_SPAWN_ERROR,
|
|
108
|
+
message: err.message,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
if (options.throwOnError) {
|
|
112
|
+
reject(new Error(err.message));
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
resolve(res);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
cp.on("close", (exitCode, signal) => {
|
|
119
|
+
cleanup();
|
|
120
|
+
const durationMs = Date.now() - startTime;
|
|
121
|
+
const ok = exitCode === 0 && !timedOut && !cancelled && !error;
|
|
122
|
+
const res = {
|
|
123
|
+
ok,
|
|
124
|
+
exitCode,
|
|
125
|
+
signal: signal || undefined,
|
|
126
|
+
stdout: stdoutBuf.trim(),
|
|
127
|
+
stderr: stderrBuf.trim(),
|
|
128
|
+
raw: new TextEncoder().encode(stdoutBuf),
|
|
129
|
+
timedOut,
|
|
130
|
+
cancelled,
|
|
131
|
+
durationMs,
|
|
132
|
+
error,
|
|
133
|
+
};
|
|
134
|
+
if (!ok && options.throwOnError) {
|
|
135
|
+
reject(new Error(stderrBuf.trim() || `Process exited with code ${exitCode}`));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
resolve(res);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
async spawn(command, args = [], options = {}) {
|
|
144
|
+
return this.exec(command, args, options);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import type { ActionDefinition, ActionRef, ExecutionResult, Logger, ProcessAPI, ProgressReporter } from "@actiondock/sdk";
|
|
2
|
+
import type { ProjectConfig } from "../project/types.js";
|
|
3
|
+
import type { RuntimeStorage } from "../storage/types.js";
|
|
4
|
+
import type { Clock } from "./clock.js";
|
|
5
|
+
import type { RuntimePlatform } from "../platform/types.js";
|
|
6
|
+
export { RUN_REPOSITORY_UNAVAILABLE, RUN_PERSISTENCE_FAILED, INPUT_NOT_JSON, OUTPUT_NOT_JSON, ACTION_SUBRUN_LIMIT, MAX_SUBRUNS_REACHED, ACTION_CALL_CYCLE, ACTION_CYCLE_DETECTED, ACTION_MAX_DEPTH_EXCEEDED, } from "../errors.js";
|
|
7
|
+
/**
|
|
8
|
+
* 校验值是否为合法的 JSON 兼容结构,严禁 NaN、Infinity、循环引用及不可序列化类型。
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateJsonValue(val: unknown, seen?: WeakSet<object>): {
|
|
11
|
+
valid: true;
|
|
12
|
+
} | {
|
|
13
|
+
valid: false;
|
|
14
|
+
reason: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* ActionRunner 初始化配置选项。
|
|
18
|
+
*/
|
|
19
|
+
export interface RunnerOptions {
|
|
20
|
+
/** 运行所属的 Package ID */
|
|
21
|
+
packageId: string;
|
|
22
|
+
/** 持久化运行时存储实例(SQLite) */
|
|
23
|
+
storage?: RuntimeStorage;
|
|
24
|
+
/** 全局共享持久化存储实例(SQLite,用于单例池化避免泄漏) */
|
|
25
|
+
globalStorage?: RuntimeStorage;
|
|
26
|
+
/** 项目根目录绝对路径 */
|
|
27
|
+
projectRoot?: string;
|
|
28
|
+
/** 项目元数据配置 */
|
|
29
|
+
projectConfig?: ProjectConfig;
|
|
30
|
+
/** CLI 或上层注入的临时配置覆盖项 */
|
|
31
|
+
configOverrides?: Record<string, unknown>;
|
|
32
|
+
/** 预加载的 Action 映射表 */
|
|
33
|
+
actions?: Map<string, ActionDefinition>;
|
|
34
|
+
/** 外部注入的进程执行器 */
|
|
35
|
+
process?: ProcessAPI;
|
|
36
|
+
/** 可选的时间与时钟源(默认使用存储内嵌时钟或系统时间) */
|
|
37
|
+
clock?: Clock;
|
|
38
|
+
/** 可选的底层运行时平台契约 */
|
|
39
|
+
platform?: RuntimePlatform;
|
|
40
|
+
/** 动态解析跨包或未注册 Action 的委托函数 */
|
|
41
|
+
actionResolver?: (ref: ActionRef | string, currentPackageId?: string) => ActionDefinition | undefined | Promise<ActionDefinition | undefined>;
|
|
42
|
+
/** 最大调用嵌套深度限制(防死循环/过深调用链,默认 16) */
|
|
43
|
+
maxCallDepth?: number;
|
|
44
|
+
/** 最大并发子任务数限制(默认 64) */
|
|
45
|
+
maxSubRuns?: number;
|
|
46
|
+
/** 跨包存储工厂 */
|
|
47
|
+
getStorageForPackage?: (packageId: string, projectRoot?: string) => RuntimeStorage;
|
|
48
|
+
/** 跨包运行上下文解析委托函数 */
|
|
49
|
+
packageContextResolver?: (packageId: string) => Promise<{
|
|
50
|
+
projectRoot?: string;
|
|
51
|
+
projectConfig?: ProjectConfig;
|
|
52
|
+
storage: RuntimeStorage;
|
|
53
|
+
actions?: Map<string, ActionDefinition>;
|
|
54
|
+
} | undefined> | {
|
|
55
|
+
projectRoot?: string;
|
|
56
|
+
projectConfig?: ProjectConfig;
|
|
57
|
+
storage: RuntimeStorage;
|
|
58
|
+
actions?: Map<string, ActionDefinition>;
|
|
59
|
+
} | undefined;
|
|
60
|
+
/** 自定义 ActionDock 用户家目录(用于测试隔离与多租户环境) */
|
|
61
|
+
customHome?: string;
|
|
62
|
+
/** 执行宿主会话标识 */
|
|
63
|
+
hostSessionId?: string;
|
|
64
|
+
}
|
|
65
|
+
/** ActionRunnerOptions 别名兼容 */
|
|
66
|
+
export type ActionRunnerOptions = RunnerOptions;
|
|
67
|
+
/**
|
|
68
|
+
* 启动 Action 执行时的可选控制参数。
|
|
69
|
+
*/
|
|
70
|
+
export interface ExecutionStartOptions {
|
|
71
|
+
/** 显式指定的运行 ID */
|
|
72
|
+
runId?: string;
|
|
73
|
+
/** 根运行 ID */
|
|
74
|
+
rootRunId?: string;
|
|
75
|
+
/** 父级运行 ID(嵌套调用场景下建立调用链树) */
|
|
76
|
+
parentRunId?: string;
|
|
77
|
+
/** 包物理实例标识 */
|
|
78
|
+
packageInstanceId?: string;
|
|
79
|
+
/** 快照代次标识 */
|
|
80
|
+
generationId?: string;
|
|
81
|
+
/** 执行所有者标识 */
|
|
82
|
+
ownerId?: string;
|
|
83
|
+
/** 执行宿主会话标识 */
|
|
84
|
+
hostSessionId?: string;
|
|
85
|
+
/** 调用栈数组(用于检测 A -> B -> A 环路死锁) */
|
|
86
|
+
callStack?: string[];
|
|
87
|
+
/** 外部传入的 AbortSignal 取消信号 */
|
|
88
|
+
signal?: AbortSignal;
|
|
89
|
+
/** 最大超时时间(毫秒),超时将自动中止执行并标记为 ACTION_TIMEOUT */
|
|
90
|
+
timeoutMs?: number;
|
|
91
|
+
/** 最大调用深度覆盖 */
|
|
92
|
+
maxCallDepth?: number;
|
|
93
|
+
/** 外部注入的进程执行器 */
|
|
94
|
+
process?: ProcessAPI;
|
|
95
|
+
/** 可选的底层运行时平台契约 */
|
|
96
|
+
platform?: RuntimePlatform;
|
|
97
|
+
/** 外部注入的进度报告器 */
|
|
98
|
+
progress?: ProgressReporter;
|
|
99
|
+
/** 外部注入的日志记录器 */
|
|
100
|
+
logger?: Logger;
|
|
101
|
+
/** 执行级临时配置覆盖项 */
|
|
102
|
+
configOverrides?: Record<string, unknown>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 异步执行句柄,支持获取执行结果 Promise 与主动取消操作。
|
|
106
|
+
*/
|
|
107
|
+
export interface ExecutionHandle {
|
|
108
|
+
/** 本次执行生成的全局唯一运行 ID */
|
|
109
|
+
runId: string;
|
|
110
|
+
/** 最终执行结果信封 Promise */
|
|
111
|
+
result: Promise<ExecutionResult>;
|
|
112
|
+
/**
|
|
113
|
+
* 取消当前正在执行的任务
|
|
114
|
+
* @param reason 取消原因
|
|
115
|
+
* @returns 是否成功触发取消
|
|
116
|
+
*/
|
|
117
|
+
cancel(reason?: string): boolean;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Action 解析结果判别联合类型。
|
|
121
|
+
*/
|
|
122
|
+
export type ActionResolution = {
|
|
123
|
+
status: "found";
|
|
124
|
+
action: ActionDefinition;
|
|
125
|
+
} | {
|
|
126
|
+
status: "not_found";
|
|
127
|
+
reason?: string;
|
|
128
|
+
} | {
|
|
129
|
+
status: "load_failed";
|
|
130
|
+
error: Error;
|
|
131
|
+
packageId: string;
|
|
132
|
+
projectRoot: string;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* ActionDock 核心执行引擎(ActionRunner)。
|
|
136
|
+
*
|
|
137
|
+
* 职责:
|
|
138
|
+
* - 负责 Action 执行的全生命周期管理(校验、隔离、跟踪、落库)。
|
|
139
|
+
* - 入参 (inputSchema) 与出参 (outputSchema) 的 JSON Schema 严格校验。
|
|
140
|
+
* - 嵌套 Action 相互调用的环路检测(Cycle Detection)。
|
|
141
|
+
* - 超时 (Timeout) 与中断信号 (AbortSignal) 竞态控制。
|
|
142
|
+
* - 自动记录并持久化 RunRecord 运行记录至 SQLite 存储。
|
|
143
|
+
*/
|
|
144
|
+
export declare class ActionRunner {
|
|
145
|
+
private packageId;
|
|
146
|
+
private storage;
|
|
147
|
+
private globalStorage?;
|
|
148
|
+
private projectRoot?;
|
|
149
|
+
private projectConfig?;
|
|
150
|
+
private configOverrides;
|
|
151
|
+
private actions;
|
|
152
|
+
private clock?;
|
|
153
|
+
private process?;
|
|
154
|
+
private platform?;
|
|
155
|
+
private maxCallDepth;
|
|
156
|
+
private maxSubRuns;
|
|
157
|
+
private activeSubRuns;
|
|
158
|
+
private packageRunners;
|
|
159
|
+
private actionResolver?;
|
|
160
|
+
private getStorageForPackage?;
|
|
161
|
+
private packageContextResolver?;
|
|
162
|
+
private customHome?;
|
|
163
|
+
private hostSessionId?;
|
|
164
|
+
constructor(options: RunnerOptions);
|
|
165
|
+
getStorage(): RuntimeStorage;
|
|
166
|
+
getPackageRunners(): Map<string, ActionRunner>;
|
|
167
|
+
/**
|
|
168
|
+
* 注册单个 Action 到当前 Runner。
|
|
169
|
+
*/
|
|
170
|
+
registerAction(id: string, action: ActionDefinition): void;
|
|
171
|
+
registerAction(action: ({
|
|
172
|
+
id: string;
|
|
173
|
+
action?: ActionDefinition;
|
|
174
|
+
} & Partial<ActionDefinition>) | ActionDefinition): void;
|
|
175
|
+
/**
|
|
176
|
+
* 根据 ID 检索注册的 Action。
|
|
177
|
+
*/
|
|
178
|
+
getAction(id: string): ActionDefinition | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* 动态解析 Action(支持本地注册表、自定义解析器委托与已链接包目录索引检索)。
|
|
181
|
+
*
|
|
182
|
+
* @param actionOrRef Action 定义对象、引用或标识符
|
|
183
|
+
* @returns 解析判别联合结果(found | not_found | load_failed)
|
|
184
|
+
*/
|
|
185
|
+
resolveAction(actionOrRef: ActionDefinition | ActionRef | string): Promise<ActionResolution>;
|
|
186
|
+
/**
|
|
187
|
+
* 获取当前 Runner 已注册的所有 Action 列表。
|
|
188
|
+
*/
|
|
189
|
+
listActions(): ActionDefinition[];
|
|
190
|
+
/**
|
|
191
|
+
* 注入或更新跨包运行上下文解析委托。
|
|
192
|
+
*/
|
|
193
|
+
setPackageContextResolver(resolver: (packageId: string) => Promise<{
|
|
194
|
+
projectRoot?: string;
|
|
195
|
+
projectConfig?: ProjectConfig;
|
|
196
|
+
storage: RuntimeStorage;
|
|
197
|
+
actions?: Map<string, ActionDefinition>;
|
|
198
|
+
} | undefined> | {
|
|
199
|
+
projectRoot?: string;
|
|
200
|
+
projectConfig?: ProjectConfig;
|
|
201
|
+
storage: RuntimeStorage;
|
|
202
|
+
actions?: Map<string, ActionDefinition>;
|
|
203
|
+
} | undefined): void;
|
|
204
|
+
/**
|
|
205
|
+
* 跨包运行时解析与获取(确保跨包执行具备独立的配置、存储、状态与 Action 注册表)。
|
|
206
|
+
*/
|
|
207
|
+
resolveTargetPackageRunner(targetPackageId: string): Promise<ActionRunner | undefined>;
|
|
208
|
+
/**
|
|
209
|
+
* 异步启动 Action 的执行并立即返回 ExecutionHandle 句柄。
|
|
210
|
+
*
|
|
211
|
+
* @param actionOrId Action 定义对象、引用或标识符
|
|
212
|
+
* @param input 传递给 Action 的输入数据
|
|
213
|
+
* @param options 执行控制选项(超时、取消信号、父运行 ID 等)
|
|
214
|
+
* @returns 包含 runId、result Promise 和 cancel 方法的执行句柄
|
|
215
|
+
*/
|
|
216
|
+
start(actionOrId: ActionDefinition | ActionRef | string, input?: unknown, options?: ExecutionStartOptions): ExecutionHandle;
|
|
217
|
+
/**
|
|
218
|
+
* 计算根运行标识(优先显式 rootRunId,其次 parentRunId,最后自身 runId)。
|
|
219
|
+
*/
|
|
220
|
+
private computeRootRunId;
|
|
221
|
+
/**
|
|
222
|
+
* 预解析执行目标并装配运行期共享上下文对象(runId、目标标识、时钟源与调用栈快照)。
|
|
223
|
+
*/
|
|
224
|
+
private prepareRunContext;
|
|
225
|
+
/**
|
|
226
|
+
* 为匿名传入的 Action 定义对象解析或分配稳定标识。
|
|
227
|
+
*/
|
|
228
|
+
private resolveAnonymousActionId;
|
|
229
|
+
/**
|
|
230
|
+
* 尝试将 failed 终态初始记录写入存储(非法输入场景,存储异常静默忽略)。
|
|
231
|
+
*/
|
|
232
|
+
private tryPersistInitialRun;
|
|
233
|
+
/**
|
|
234
|
+
* 构建 running 初始记录并强制写入存储(存储不可用时抛出 RUN_REPOSITORY_UNAVAILABLE)。
|
|
235
|
+
*/
|
|
236
|
+
private persistInitialRun;
|
|
237
|
+
/**
|
|
238
|
+
* 依据运行期上下文构造 RunRecord 初始记录。
|
|
239
|
+
*/
|
|
240
|
+
private buildInitialRunRecord;
|
|
241
|
+
/**
|
|
242
|
+
* 创建运行终态收敛器:封装终态去重、超时定时器清理与落库异常捕获。
|
|
243
|
+
*/
|
|
244
|
+
private createRunFinalizer;
|
|
245
|
+
/**
|
|
246
|
+
* 调用嵌套深度限制检测(超限时返回 ACTION_CALL_CYCLE 错误)。
|
|
247
|
+
*/
|
|
248
|
+
private checkCallDepth;
|
|
249
|
+
/**
|
|
250
|
+
* 计算调用键并执行环路死锁检测(命中时返回携带错误的调用键结果)。
|
|
251
|
+
*/
|
|
252
|
+
private computeCallKey;
|
|
253
|
+
/**
|
|
254
|
+
* 输入参数 JSON Schema 校验(若 action 已就绪,返回校验错误或 undefined)。
|
|
255
|
+
*/
|
|
256
|
+
private checkActionInputSchema;
|
|
257
|
+
/**
|
|
258
|
+
* 构建 ActionContext 运行时上下文(内嵌子 Action 调用委托提为私有方法)。
|
|
259
|
+
*/
|
|
260
|
+
private buildActionContext;
|
|
261
|
+
/**
|
|
262
|
+
* 子 Action 调用委托:并发上限守卫、uses 跨包声明校验与子执行派发。
|
|
263
|
+
*/
|
|
264
|
+
private invokeChildAction;
|
|
265
|
+
/**
|
|
266
|
+
* 校验跨包子调用是否已在 uses 声明中授权(未声明时抛出 UNDECLARED_ACTION_DEPENDENCY)。
|
|
267
|
+
*/
|
|
268
|
+
private assertDeclaredUses;
|
|
269
|
+
/**
|
|
270
|
+
* 解析子调用应使用的 Runner(本包或已解析的目标包 Runner)。
|
|
271
|
+
*/
|
|
272
|
+
private resolveChildRunner;
|
|
273
|
+
/**
|
|
274
|
+
* 执行 Action 业务逻辑并与取消/超时信号进行竞态,返回执行结果信封 Promise。
|
|
275
|
+
*/
|
|
276
|
+
private raceExecutionAndAbort;
|
|
277
|
+
/**
|
|
278
|
+
* 输出结果 Schema 校验(返回校验错误或 undefined)。
|
|
279
|
+
*/
|
|
280
|
+
private checkActionOutputSchema;
|
|
281
|
+
/**
|
|
282
|
+
* 异常分类收敛:超时、取消与业务失败分别映射为对应终态与错误码。
|
|
283
|
+
*/
|
|
284
|
+
private classifyExecutionError;
|
|
285
|
+
/**
|
|
286
|
+
* 同步等待方式执行指定 Action,直接返回 ExecutionResult 信封结果。
|
|
287
|
+
*
|
|
288
|
+
* @param actionOrId Action 定义对象、引用或标识符
|
|
289
|
+
* @param input 输入参数
|
|
290
|
+
* @param options 执行控制选项
|
|
291
|
+
*/
|
|
292
|
+
execute(actionOrId: ActionDefinition | ActionRef | string, input?: unknown, options?: ExecutionStartOptions): Promise<ExecutionResult>;
|
|
293
|
+
}
|