@actiondock/core 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 +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 +1 -1
- package/dist/catalog/action-index.js +93 -0
- package/dist/catalog/action-resolver.d.ts +2 -2
- package/dist/catalog/action-resolver.js +95 -0
- package/dist/catalog/index.d.ts +5 -5
- package/dist/catalog/index.js +5 -0
- package/dist/catalog/location-registry.d.ts +5 -5
- package/dist/catalog/location-registry.js +138 -0
- package/dist/catalog/package-catalog.d.ts +2 -2
- package/dist/catalog/package-catalog.js +76 -0
- package/dist/catalog/types.d.ts +2 -2
- package/dist/catalog/types.js +1 -0
- package/dist/doctor/doctor.d.ts +2 -1
- package/dist/doctor/doctor.js +613 -0
- package/dist/doctor/index.d.ts +2 -2
- package/dist/doctor/index.js +2 -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 -2
- package/dist/execution/index.js +2 -0
- package/dist/execution/service.d.ts +46 -41
- package/dist/execution/service.js +633 -0
- package/dist/execution/types.d.ts +59 -2
- package/dist/execution/types.js +1 -0
- package/dist/export/index.d.ts +1 -1
- package/dist/export/index.js +1 -0
- package/dist/export/templates.d.ts +45 -7
- package/dist/export/templates.js +631 -0
- package/dist/filter/index.d.ts +1 -1
- package/dist/filter/index.js +1 -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 -16
- package/dist/index.js +20 -8458
- 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 +58 -12
- package/dist/profile/client.js +467 -0
- package/dist/profile/index.d.ts +3 -3
- package/dist/profile/index.js +3 -0
- package/dist/profile/manager.d.ts +2 -2
- package/dist/profile/manager.js +294 -0
- package/dist/profile/types.d.ts +1 -1
- package/dist/profile/types.js +1 -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 -5
- package/dist/project/index.js +10 -0
- package/dist/project/init.d.ts +3 -4
- package/dist/project/init.js +175 -0
- package/dist/project/loader.d.ts +21 -27
- 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 +6 -28
- 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 +58 -82
- package/dist/project/types.js +1 -0
- package/dist/registry/index.d.ts +5 -2
- 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 +32 -11
- 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 +1 -1
- 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 +0 -2
- package/dist/runtime/clock.js +17 -0
- package/dist/runtime/context.d.ts +16 -5
- package/dist/runtime/context.js +242 -0
- package/dist/runtime/env.d.ts +3 -1
- package/dist/runtime/env.js +159 -0
- package/dist/runtime/events.d.ts +46 -14
- package/dist/runtime/events.js +604 -0
- package/dist/runtime/execution-manager.d.ts +1 -1
- package/dist/runtime/execution-manager.js +66 -0
- package/dist/runtime/index.d.ts +10 -9
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/module-loader.d.ts +0 -8
- package/dist/runtime/module-loader.js +16 -0
- package/dist/runtime/process.d.ts +2 -4
- package/dist/runtime/process.js +146 -0
- package/dist/runtime/runner.d.ts +117 -10
- package/dist/runtime/runner.js +984 -0
- package/dist/runtime/standalone.d.ts +68 -19
- package/dist/runtime/standalone.js +536 -0
- package/dist/schema/validator.js +122 -0
- package/dist/server/body.js +93 -0
- package/dist/server/index.d.ts +5 -6
- package/dist/server/index.js +5 -0
- package/dist/server/routes/actions.d.ts +2 -2
- package/dist/server/routes/actions.js +298 -0
- package/dist/server/routes/common.d.ts +28 -17
- package/dist/server/routes/common.js +104 -0
- package/dist/server/routes/config.d.ts +2 -1
- package/dist/server/routes/config.js +173 -0
- package/dist/server/routes/doctor.d.ts +2 -2
- package/dist/server/routes/doctor.js +63 -0
- package/dist/server/routes/health.d.ts +2 -2
- package/dist/server/routes/health.js +35 -0
- package/dist/server/routes/index.d.ts +9 -9
- package/dist/server/routes/index.js +9 -0
- package/dist/server/routes/info.d.ts +4 -2
- package/dist/server/routes/info.js +158 -0
- package/dist/server/routes/playbooks.d.ts +2 -2
- package/dist/server/routes/playbooks.js +134 -0
- package/dist/server/routes/runs.d.ts +2 -2
- package/dist/server/routes/runs.js +343 -0
- package/dist/server/routes/state.d.ts +2 -1
- package/dist/server/routes/state.js +169 -0
- package/dist/server/security.d.ts +11 -4
- package/dist/server/security.js +101 -0
- package/dist/server/server.d.ts +6 -6
- package/dist/server/server.js +355 -0
- package/dist/server/types.d.ts +27 -8
- 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 +4 -10
- package/dist/storage/driver.js +59 -0
- package/dist/storage/index.d.ts +30 -10
- 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 +12 -5
- 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 +19 -6
- package/dist/storage/sqlite.js +689 -0
- package/dist/storage/types.d.ts +57 -6
- 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 +22 -2
- package/dist/utils/index.js +180 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +4 -0
- package/package.json +6 -7
- package/dist/build/index.d.ts +0 -1
- package/dist/build/templates.d.ts +0 -19
- package/dist/server/runtime-registry.d.ts +0 -78
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ActionDockTarget, TargetOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* 工厂函数:统一创建 ActionDockTarget 实例。
|
|
4
|
+
* 依据传入参数自动决策创建 LocalActionDockTarget 或 RemoteActionDockTarget。
|
|
5
|
+
*/
|
|
6
|
+
export declare function createActionDockTarget(options?: TargetOptions): Promise<ActionDockTarget>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createActionDockApp } from "../app/app.js";
|
|
2
|
+
import { createActionDockHost } from "../host/host.js";
|
|
3
|
+
import { LocalActionDockTarget } from "./local.js";
|
|
4
|
+
import { RemoteActionDockTarget } from "./remote.js";
|
|
5
|
+
/**
|
|
6
|
+
* 工厂函数:统一创建 ActionDockTarget 实例。
|
|
7
|
+
* 依据传入参数自动决策创建 LocalActionDockTarget 或 RemoteActionDockTarget。
|
|
8
|
+
*/
|
|
9
|
+
export async function createActionDockTarget(options = {}) {
|
|
10
|
+
if (options.type === "ipc") {
|
|
11
|
+
const { IpcActionDockTarget } = await import("../ipc/target.js");
|
|
12
|
+
return new IpcActionDockTarget(options);
|
|
13
|
+
}
|
|
14
|
+
if (options.type === "remote" ||
|
|
15
|
+
("serverUrl" in options && Boolean(options.serverUrl))) {
|
|
16
|
+
return new RemoteActionDockTarget(options);
|
|
17
|
+
}
|
|
18
|
+
const localOpts = options;
|
|
19
|
+
if (localOpts.host) {
|
|
20
|
+
return new LocalActionDockTarget(localOpts.host);
|
|
21
|
+
}
|
|
22
|
+
if (localOpts.app) {
|
|
23
|
+
return new LocalActionDockTarget(localOpts.app);
|
|
24
|
+
}
|
|
25
|
+
if (localOpts.appOptions) {
|
|
26
|
+
const app = await createActionDockApp(localOpts.appOptions);
|
|
27
|
+
return new LocalActionDockTarget(app);
|
|
28
|
+
}
|
|
29
|
+
const host = await createActionDockHost({
|
|
30
|
+
scanLinkedPackages: localOpts.scanLinkedPackages ?? true,
|
|
31
|
+
...localOpts,
|
|
32
|
+
...(localOpts.hostOptions || {}),
|
|
33
|
+
});
|
|
34
|
+
return new LocalActionDockTarget(host);
|
|
35
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import type { ActionRef, ExecutionEvent, ExecutionResult, JsonValue, RunRecord } from "@actiondock/sdk";
|
|
2
|
+
import type { ActionDockApp, ActionDockAppOptions, ActionSpec, ActionSummary, ListActionsOptions, PackageInfo, PlaybookSpec, PlaybookSummary } from "../app/types.js";
|
|
3
|
+
import type { CancelResult, ExecuteOptions, ExecutionTicket } from "../execution/types.js";
|
|
4
|
+
import type { ActionDockHost, ActionDockHostOptions } from "../host/types.js";
|
|
5
|
+
import type { RuntimePlatform } from "../platform/types.js";
|
|
6
|
+
import type { StateEntry } from "../storage/types.js";
|
|
7
|
+
/**
|
|
8
|
+
* 统一协议版本常量。
|
|
9
|
+
*/
|
|
10
|
+
export declare const ACTIONDOCK_PROTOCOL_VERSION = "2.0";
|
|
11
|
+
/**
|
|
12
|
+
* Target 错误码常量。
|
|
13
|
+
*/
|
|
14
|
+
export declare const TARGET_PROTOCOL_UNSUPPORTED = "TARGET_PROTOCOL_UNSUPPORTED";
|
|
15
|
+
export declare const TARGET_CAPABILITY_UNAVAILABLE = "TARGET_CAPABILITY_UNAVAILABLE";
|
|
16
|
+
export declare const TARGET_RESULT_UNKNOWN = "TARGET_RESULT_UNKNOWN";
|
|
17
|
+
/**
|
|
18
|
+
* 结构化 Target 异常类。
|
|
19
|
+
*/
|
|
20
|
+
export declare class TargetError extends Error {
|
|
21
|
+
readonly code: string;
|
|
22
|
+
readonly details?: Record<string, unknown>;
|
|
23
|
+
constructor(code: string, message: string, details?: Record<string, unknown>);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 关闭超时异常类。
|
|
27
|
+
*/
|
|
28
|
+
export declare class CloseTimeoutError extends Error {
|
|
29
|
+
readonly runIds?: string[];
|
|
30
|
+
constructor(message?: string, runIds?: string[]);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 幂等性保留策略。
|
|
34
|
+
*/
|
|
35
|
+
export interface IdempotencyPolicy {
|
|
36
|
+
/** 去重记录保留时长(毫秒) */
|
|
37
|
+
retentionMs?: number;
|
|
38
|
+
/** 去重请求头标识字段名 */
|
|
39
|
+
header?: string;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 统一目标自省元数据信息。
|
|
44
|
+
*/
|
|
45
|
+
export interface TargetInfo {
|
|
46
|
+
/** 目标宿主唯一标识 */
|
|
47
|
+
id: string;
|
|
48
|
+
/** 目标宿主名称 */
|
|
49
|
+
name: string;
|
|
50
|
+
/** 统一通信协议版本 */
|
|
51
|
+
protocolVersion: string;
|
|
52
|
+
/** 已加载或已发现的包清单 */
|
|
53
|
+
packages: PackageInfo[];
|
|
54
|
+
/** 服务端声明的能力集合 */
|
|
55
|
+
capabilities: string[];
|
|
56
|
+
/** 去重记录保留与幂等策略 */
|
|
57
|
+
idempotencyPolicy?: IdempotencyPolicy;
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 配置项安全视图契约。
|
|
62
|
+
* 屏蔽敏感配置原文,仅暴露是否已配置、是否为秘密及实际解析来源。
|
|
63
|
+
*/
|
|
64
|
+
export interface ConfigValueView {
|
|
65
|
+
/** 配置项键名 */
|
|
66
|
+
key: string;
|
|
67
|
+
/** 是否已显式配置或存在有效值 */
|
|
68
|
+
configured: boolean;
|
|
69
|
+
/** 是否为秘密敏感配置 */
|
|
70
|
+
secret: boolean;
|
|
71
|
+
/** 配置值实际解析来源 */
|
|
72
|
+
source: string;
|
|
73
|
+
/** 非秘密配置的实际数据值 */
|
|
74
|
+
value?: JsonValue;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 状态作用域与筛选控制选项。
|
|
78
|
+
*/
|
|
79
|
+
export interface StateScopeOptions {
|
|
80
|
+
/** 显式绑定的 Action 标识(可选,用于在扁平调用时直接定位 Action 命名空间) */
|
|
81
|
+
actionId?: string;
|
|
82
|
+
/** 显式子命名空间(相对于 Action 根命名空间) */
|
|
83
|
+
namespace?: string;
|
|
84
|
+
/** 存活有效期(秒),仅在写入状态时生效 */
|
|
85
|
+
ttl?: number;
|
|
86
|
+
/** 键名前缀过滤匹配 */
|
|
87
|
+
prefix?: string;
|
|
88
|
+
/** 是否清空所有条目 */
|
|
89
|
+
all?: boolean;
|
|
90
|
+
/** 是否返回完整条目详情 */
|
|
91
|
+
detail?: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* ActionDockTarget 统一调用门面契约。
|
|
95
|
+
* 为 CLI、SDK 及扩展系统屏蔽本地执行与远程调用的物理拓扑差异。
|
|
96
|
+
*/
|
|
97
|
+
export interface ActionDockTarget {
|
|
98
|
+
/** 获取统一目标自省元数据信息 */
|
|
99
|
+
info(): Promise<TargetInfo>;
|
|
100
|
+
/** 列出目标所有已加载的包清单 */
|
|
101
|
+
listPackages(): Promise<PackageInfo[]>;
|
|
102
|
+
/** 静态列出目标所有可用的 Action 摘要 */
|
|
103
|
+
listActions(options?: ListActionsOptions): Promise<ActionSummary[]>;
|
|
104
|
+
/** 静态查询并返回指定 Action 的规范结构与模式定义 */
|
|
105
|
+
describeAction(ref: ActionRef | string): Promise<ActionSpec>;
|
|
106
|
+
/** 静态列出目标所有可用的 Playbook 规程摘要 */
|
|
107
|
+
listPlaybooks(options?: {
|
|
108
|
+
intent?: string;
|
|
109
|
+
package?: string;
|
|
110
|
+
}): Promise<PlaybookSummary[]>;
|
|
111
|
+
/** 静态查询并返回指定 Playbook 的规范内容与操作指南 */
|
|
112
|
+
describePlaybook(id: string): Promise<PlaybookSpec>;
|
|
113
|
+
/** 同步执行指定 Action 并等待终态结果 */
|
|
114
|
+
runAction(ref: ActionRef | string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionResult>;
|
|
115
|
+
/** 异步启动指定 Action 并立即返回任务执行票据 */
|
|
116
|
+
startAction(ref: ActionRef | string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionTicket>;
|
|
117
|
+
/** 查询最近的任务执行记录列表 */
|
|
118
|
+
listRuns(options?: ListRunsOptions): Promise<RunRecord[]>;
|
|
119
|
+
/** 查询指定运行标识的记录详情 */
|
|
120
|
+
getRun(runId: string): Promise<RunRecord | undefined>;
|
|
121
|
+
/** 取消指定在运行的任务 */
|
|
122
|
+
cancelRun(runId: string, reason?: string): Promise<CancelResult>;
|
|
123
|
+
/** 清空历史任务运行记录 */
|
|
124
|
+
clearRuns?(options?: {
|
|
125
|
+
packageId?: string;
|
|
126
|
+
actionId?: string;
|
|
127
|
+
status?: string;
|
|
128
|
+
}): Promise<number>;
|
|
129
|
+
/** 订阅指定运行的事件流 */
|
|
130
|
+
events(runId: string, options?: {
|
|
131
|
+
after?: number | string;
|
|
132
|
+
signal?: AbortSignal;
|
|
133
|
+
maxQueueSize?: number;
|
|
134
|
+
}): AsyncIterable<ExecutionEvent>;
|
|
135
|
+
/** 获取指定包的单项配置安全视图 */
|
|
136
|
+
getConfig(packageId: string, key: string): Promise<ConfigValueView>;
|
|
137
|
+
/** 写入或覆盖指定包的配置项 */
|
|
138
|
+
setConfig(packageId: string, key: string, value: JsonValue): Promise<void>;
|
|
139
|
+
/** 删除指定包的指定配置项 */
|
|
140
|
+
deleteConfig(packageId: string, key: string): Promise<boolean>;
|
|
141
|
+
/** 列出指定包所有配置项的安全视图列表 */
|
|
142
|
+
listConfig(packageId: string): Promise<ConfigValueView[]>;
|
|
143
|
+
/** 获取指定包指定动作的作用域状态值 */
|
|
144
|
+
getState<T extends JsonValue = JsonValue>(packageId: string, actionId: string, key: string, options?: StateScopeOptions): Promise<T | undefined>;
|
|
145
|
+
/** 写入指定包指定动作的作用域状态值 */
|
|
146
|
+
setState<T extends JsonValue = JsonValue>(packageId: string, actionId: string, key: string, value: T, options?: StateScopeOptions): Promise<void>;
|
|
147
|
+
/** 删除指定包指定动作的作用域状态项 */
|
|
148
|
+
deleteState(packageId: string, actionId: string, key: string, options?: StateScopeOptions): Promise<boolean>;
|
|
149
|
+
/** 列出指定包指定动作在存储中的状态键名列表 */
|
|
150
|
+
listStateKeys(packageId: string, actionId: string, options?: StateScopeOptions): Promise<string[]>;
|
|
151
|
+
/** 清空指定包指定动作在存储中的状态条目 */
|
|
152
|
+
clearState(packageId: string, actionId: string, options?: StateScopeOptions): Promise<number>;
|
|
153
|
+
/** 列出指定包在存储中的状态条目(含完整元数据) */
|
|
154
|
+
listStateEntries?(packageId: string, options?: any): Promise<StateEntry[]>;
|
|
155
|
+
/** 解包被包装的内部宿主或应用实例(仅本地包装型目标存在) */
|
|
156
|
+
unwrap?(): ActionDockHost | ActionDockApp | undefined;
|
|
157
|
+
/** 关闭目标连接并清理底层资源 */
|
|
158
|
+
close(options?: {
|
|
159
|
+
timeoutMs?: number;
|
|
160
|
+
}): Promise<void>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 历史任务执行记录检索查询选项。
|
|
164
|
+
*/
|
|
165
|
+
export interface ListRunsOptions {
|
|
166
|
+
/** 目标包唯一标识 */
|
|
167
|
+
packageId?: string;
|
|
168
|
+
/** Action 动作唯一标识 */
|
|
169
|
+
actionId?: string;
|
|
170
|
+
/** 运行终态状态筛选 */
|
|
171
|
+
status?: string;
|
|
172
|
+
/** 模糊意图检索模式 */
|
|
173
|
+
intent?: string;
|
|
174
|
+
/** 最大返回记录条数限制 */
|
|
175
|
+
limit?: number;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* 本地 Target 初始化选项。
|
|
179
|
+
*/
|
|
180
|
+
export interface LocalTargetOptions {
|
|
181
|
+
type?: "local";
|
|
182
|
+
/** 包装的 ActionDockHost 实例 */
|
|
183
|
+
host?: ActionDockHost;
|
|
184
|
+
/** 包装的 ActionDockApp 实例 */
|
|
185
|
+
app?: ActionDockApp;
|
|
186
|
+
/** 单包 App 初始化配置(若未提供 host/app) */
|
|
187
|
+
appOptions?: ActionDockAppOptions;
|
|
188
|
+
/** 宿主 Host 初始化配置 */
|
|
189
|
+
hostOptions?: ActionDockHostOptions;
|
|
190
|
+
/** 当前工程根目录绝对路径 */
|
|
191
|
+
projectRoot?: string;
|
|
192
|
+
/** 预注册包配置列表 */
|
|
193
|
+
packages?: Array<ActionDockApp | ActionDockAppOptions>;
|
|
194
|
+
/** 自定义 ActionDock 家目录 */
|
|
195
|
+
customHome?: string;
|
|
196
|
+
/** 是否采用纯内存运行模式 */
|
|
197
|
+
inMemory?: boolean;
|
|
198
|
+
/** 自定义全局数据存储目录 */
|
|
199
|
+
dataDir?: string;
|
|
200
|
+
/** 是否扫描已软链接的外部包 */
|
|
201
|
+
scanLinkedPackages?: boolean;
|
|
202
|
+
/** 运行时平台适配 */
|
|
203
|
+
platform?: RuntimePlatform;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* 远程 Target 初始化选项。
|
|
207
|
+
*/
|
|
208
|
+
export interface RemoteTargetOptions {
|
|
209
|
+
type?: "remote";
|
|
210
|
+
/** 远端 ActionDock 服务 HTTP 根地址 */
|
|
211
|
+
serverUrl: string;
|
|
212
|
+
/** 鉴权 Bearer Token(可选) */
|
|
213
|
+
token?: string;
|
|
214
|
+
/** 是否允许向非回环地址发送明文 HTTP 请求(默认 false) */
|
|
215
|
+
allowInsecureHttp?: boolean;
|
|
216
|
+
/** 请求超时时间(毫秒) */
|
|
217
|
+
timeoutMs?: number;
|
|
218
|
+
/** 轮询等待基准底线超时时间(毫秒,默认 60000ms) */
|
|
219
|
+
baseTimeoutMs?: number;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* 监督进程 IPC 目标初始化选项。
|
|
223
|
+
*/
|
|
224
|
+
export interface IpcTargetOptions {
|
|
225
|
+
type?: "ipc";
|
|
226
|
+
/** 已启动的子进程实例(需具备 IPC 通道) */
|
|
227
|
+
childProcess?: any;
|
|
228
|
+
/** 待启动的脚本物理路径 */
|
|
229
|
+
scriptPath?: string;
|
|
230
|
+
/** 启动参数 */
|
|
231
|
+
scriptArgs?: string[];
|
|
232
|
+
/** 工作目录 */
|
|
233
|
+
cwd?: string;
|
|
234
|
+
/** 环境变量 */
|
|
235
|
+
env?: Record<string, string | undefined>;
|
|
236
|
+
/** 诊断流单流最大转发字节数 */
|
|
237
|
+
maxDiagnosticBytes?: number;
|
|
238
|
+
/** 诊断流每秒最大字节速率 */
|
|
239
|
+
maxDiagnosticRate?: number;
|
|
240
|
+
/** 诊断流目标输出 */
|
|
241
|
+
diagnosticTarget?: any;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Target 统一工厂选项参数。
|
|
245
|
+
*/
|
|
246
|
+
export type TargetOptions = LocalTargetOptions | RemoteTargetOptions | IpcTargetOptions;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一协议版本常量。
|
|
3
|
+
*/
|
|
4
|
+
export const ACTIONDOCK_PROTOCOL_VERSION = "2.0";
|
|
5
|
+
/**
|
|
6
|
+
* Target 错误码常量。
|
|
7
|
+
*/
|
|
8
|
+
export const TARGET_PROTOCOL_UNSUPPORTED = "TARGET_PROTOCOL_UNSUPPORTED";
|
|
9
|
+
export const TARGET_CAPABILITY_UNAVAILABLE = "TARGET_CAPABILITY_UNAVAILABLE";
|
|
10
|
+
export const TARGET_RESULT_UNKNOWN = "TARGET_RESULT_UNKNOWN";
|
|
11
|
+
/**
|
|
12
|
+
* 结构化 Target 异常类。
|
|
13
|
+
*/
|
|
14
|
+
export class TargetError extends Error {
|
|
15
|
+
code;
|
|
16
|
+
details;
|
|
17
|
+
constructor(code, message, details) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "TargetError";
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.details = details;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 关闭超时异常类。
|
|
26
|
+
*/
|
|
27
|
+
export class CloseTimeoutError extends Error {
|
|
28
|
+
runIds;
|
|
29
|
+
constructor(message = "Target close operation timed out", runIds) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "CloseTimeoutError";
|
|
32
|
+
this.runIds = runIds;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 跨运行时安全查找可执行文件绝对物理路径。
|
|
3
|
+
*
|
|
4
|
+
* 注意:本函数为同步实现,内部同步遍历 PATH 逐个探测物理文件存在性;
|
|
5
|
+
* 当前全部调用方(doctor 体检与测试 CLI 桥)均为同步链路,serve 链路未使用本函数,
|
|
6
|
+
* 因此暂不提供异步版本。若后续异步链路需要,应另行新增异步实现而非改造本函数。
|
|
7
|
+
*/
|
|
8
|
+
export declare function findExecutable(command: string): string | null;
|
|
2
9
|
/**
|
|
3
10
|
* Parses duration strings like "500ms", "30s", "5m", "1h", "1d" or pure numbers into milliseconds.
|
|
4
11
|
*/
|
|
@@ -16,11 +23,24 @@ export declare const PACKAGE_ID_REGEX: RegExp;
|
|
|
16
23
|
* Validates packageId to ensure it adheres to valid naming conventions and prevents path traversal.
|
|
17
24
|
*/
|
|
18
25
|
export declare function assertValidPackageId(packageId: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves a path to its canonical physical location.
|
|
28
|
+
* If the path exists, calls realpathSync.
|
|
29
|
+
* If not, traverses upward to find the nearest existing ancestor, resolves its symlink,
|
|
30
|
+
* and appends the non-existent relative segments.
|
|
31
|
+
*/
|
|
32
|
+
export declare function canonicalizePath(targetPath: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* 校验相对路径是否越出根目录边界。
|
|
35
|
+
* 只有当相对路径为绝对路径、等于 ".." 或以 "..[/\\]" 起始时才判定为越界,
|
|
36
|
+
* 避免形如 ..cache、..cache/file 等在根目录内部的文件或目录被误判越界。
|
|
37
|
+
*/
|
|
38
|
+
export declare function isPathOutsideBoundary(rel: string): boolean;
|
|
19
39
|
/**
|
|
20
40
|
* Ensures that a given path stays strictly within the specified root boundary,
|
|
21
41
|
* preventing relative directory escape (..) and symlink jailbreak.
|
|
22
42
|
* Traverses upward to the nearest existing ancestor directory to resolve symlinks
|
|
23
|
-
*
|
|
43
|
+
* symmetrically for both root and target paths.
|
|
24
44
|
*/
|
|
25
45
|
export declare function assertPathWithinRoot(rootDir: string, targetPath: string, fieldName?: string): void;
|
|
26
46
|
/**
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
/**
|
|
5
|
+
* 跨运行时安全查找可执行文件绝对物理路径。
|
|
6
|
+
*
|
|
7
|
+
* 注意:本函数为同步实现,内部同步遍历 PATH 逐个探测物理文件存在性;
|
|
8
|
+
* 当前全部调用方(doctor 体检与测试 CLI 桥)均为同步链路,serve 链路未使用本函数,
|
|
9
|
+
* 因此暂不提供异步版本。若后续异步链路需要,应另行新增异步实现而非改造本函数。
|
|
10
|
+
*/
|
|
11
|
+
export function findExecutable(command) {
|
|
12
|
+
if (typeof globalThis.Bun !== "undefined" && typeof globalThis.Bun.which === "function") {
|
|
13
|
+
try {
|
|
14
|
+
const bPath = globalThis.Bun.which(command);
|
|
15
|
+
if (bPath)
|
|
16
|
+
return bPath;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// ignore
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const hasPathSep = command.includes("/") || command.includes("\\");
|
|
23
|
+
if (hasPathSep) {
|
|
24
|
+
return existsSync(command) ? command : null;
|
|
25
|
+
}
|
|
26
|
+
const pathEnv = process.env.PATH || "";
|
|
27
|
+
const dirs = pathEnv.split(delimiter);
|
|
28
|
+
const isWindows = process.platform === "win32";
|
|
29
|
+
const pathext = isWindows
|
|
30
|
+
? (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";")
|
|
31
|
+
: [""];
|
|
32
|
+
for (const dir of dirs) {
|
|
33
|
+
if (!dir)
|
|
34
|
+
continue;
|
|
35
|
+
for (const ext of pathext) {
|
|
36
|
+
const candidate = join(dir, isWindows && !command.includes(".") ? command + ext : command);
|
|
37
|
+
if (existsSync(candidate)) {
|
|
38
|
+
return candidate;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parses duration strings like "500ms", "30s", "5m", "1h", "1d" or pure numbers into milliseconds.
|
|
46
|
+
*/
|
|
47
|
+
export function parseDuration(input) {
|
|
48
|
+
if (!input || !input.trim()) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const str = input.trim();
|
|
52
|
+
if (/^\d+$/.test(str)) {
|
|
53
|
+
return parseInt(str, 10);
|
|
54
|
+
}
|
|
55
|
+
const match = str.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h|d)$/i);
|
|
56
|
+
if (!match) {
|
|
57
|
+
throw new Error(`Invalid duration format: '${input}'. Supported formats: 500ms, 30s, 5m, 1h`);
|
|
58
|
+
}
|
|
59
|
+
const val = parseFloat(match[1]);
|
|
60
|
+
const unit = match[2].toLowerCase();
|
|
61
|
+
switch (unit) {
|
|
62
|
+
case "ms":
|
|
63
|
+
return Math.round(val);
|
|
64
|
+
case "s":
|
|
65
|
+
return Math.round(val * 1000);
|
|
66
|
+
case "m":
|
|
67
|
+
return Math.round(val * 60 * 1000);
|
|
68
|
+
case "h":
|
|
69
|
+
return Math.round(val * 60 * 60 * 1000);
|
|
70
|
+
case "d":
|
|
71
|
+
return Math.round(val * 24 * 60 * 60 * 1000);
|
|
72
|
+
default:
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Extracts a concise slug from a package or action identifier (e.g. '@scope/pkg' -> 'pkg', 'team.action' -> 'action').
|
|
78
|
+
*/
|
|
79
|
+
export function getPackageSlug(id) {
|
|
80
|
+
if (id.includes("/")) {
|
|
81
|
+
return id.split("/").pop();
|
|
82
|
+
}
|
|
83
|
+
if (id.includes(".")) {
|
|
84
|
+
return id.split(".").pop();
|
|
85
|
+
}
|
|
86
|
+
return id;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Resolves the root ActionDock user home directory based on customHome, ACTIONDOCK_HOME, or user homedir.
|
|
90
|
+
*/
|
|
91
|
+
export function getActionDockHome(customHome) {
|
|
92
|
+
return customHome || process.env.ACTIONDOCK_HOME || homedir();
|
|
93
|
+
}
|
|
94
|
+
export const PACKAGE_ID_REGEX = /^[a-z0-9][a-z0-9.-]*$/;
|
|
95
|
+
/**
|
|
96
|
+
* Validates packageId to ensure it adheres to valid naming conventions and prevents path traversal.
|
|
97
|
+
*/
|
|
98
|
+
export function assertValidPackageId(packageId) {
|
|
99
|
+
if (packageId === "__global__" || packageId === ":memory:") {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const isScopedLegacy = /^@[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(packageId);
|
|
103
|
+
if (!packageId ||
|
|
104
|
+
typeof packageId !== "string" ||
|
|
105
|
+
packageId.includes("..") ||
|
|
106
|
+
(!PACKAGE_ID_REGEX.test(packageId) && !isScopedLegacy)) {
|
|
107
|
+
throw new Error(`Invalid packageId '${packageId}': must match ${PACKAGE_ID_REGEX} and not contain path traversal characters`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Resolves a path to its canonical physical location.
|
|
112
|
+
* If the path exists, calls realpathSync.
|
|
113
|
+
* If not, traverses upward to find the nearest existing ancestor, resolves its symlink,
|
|
114
|
+
* and appends the non-existent relative segments.
|
|
115
|
+
*/
|
|
116
|
+
export function canonicalizePath(targetPath) {
|
|
117
|
+
let curr = resolve(targetPath);
|
|
118
|
+
const missingSegments = [];
|
|
119
|
+
while (!existsSync(curr)) {
|
|
120
|
+
const parent = dirname(curr);
|
|
121
|
+
if (parent === curr) {
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
missingSegments.unshift(basename(curr));
|
|
125
|
+
curr = parent;
|
|
126
|
+
}
|
|
127
|
+
if (existsSync(curr)) {
|
|
128
|
+
try {
|
|
129
|
+
const realCurr = realpathSync(curr);
|
|
130
|
+
return missingSegments.length > 0
|
|
131
|
+
? resolve(realCurr, ...missingSegments)
|
|
132
|
+
: realCurr;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return resolve(targetPath);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return resolve(targetPath);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 校验相对路径是否越出根目录边界。
|
|
142
|
+
* 只有当相对路径为绝对路径、等于 ".." 或以 "..[/\\]" 起始时才判定为越界,
|
|
143
|
+
* 避免形如 ..cache、..cache/file 等在根目录内部的文件或目录被误判越界。
|
|
144
|
+
*/
|
|
145
|
+
export function isPathOutsideBoundary(rel) {
|
|
146
|
+
return (isAbsolute(rel) ||
|
|
147
|
+
rel === ".." ||
|
|
148
|
+
rel.startsWith(".." + sep) ||
|
|
149
|
+
rel.startsWith("../") ||
|
|
150
|
+
rel.startsWith("..\\"));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Ensures that a given path stays strictly within the specified root boundary,
|
|
154
|
+
* preventing relative directory escape (..) and symlink jailbreak.
|
|
155
|
+
* Traverses upward to the nearest existing ancestor directory to resolve symlinks
|
|
156
|
+
* symmetrically for both root and target paths.
|
|
157
|
+
*/
|
|
158
|
+
export function assertPathWithinRoot(rootDir, targetPath, fieldName = "path") {
|
|
159
|
+
const resolvedRoot = resolve(rootDir);
|
|
160
|
+
const resolvedTarget = resolve(rootDir, targetPath);
|
|
161
|
+
const rel = relative(resolvedRoot, resolvedTarget);
|
|
162
|
+
if (isPathOutsideBoundary(rel)) {
|
|
163
|
+
throw new Error(`'${fieldName}' escapes boundary '${rootDir}': ${targetPath}`);
|
|
164
|
+
}
|
|
165
|
+
const canonicalRoot = canonicalizePath(resolvedRoot);
|
|
166
|
+
const canonicalTarget = canonicalizePath(resolvedTarget);
|
|
167
|
+
const relReal = relative(canonicalRoot, canonicalTarget);
|
|
168
|
+
if (isPathOutsideBoundary(relReal)) {
|
|
169
|
+
throw new Error(`'${fieldName}' symlink resolves outside boundary '${rootDir}': ${targetPath}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Backwards-compatible alias for assertPathWithinRoot targeting project roots.
|
|
174
|
+
*/
|
|
175
|
+
export function assertWithinProjectRoot(projectRoot, subDir, fieldName) {
|
|
176
|
+
if (isAbsolute(subDir)) {
|
|
177
|
+
throw new Error(`'${fieldName}' cannot be an absolute path: ${subDir}`);
|
|
178
|
+
}
|
|
179
|
+
assertPathWithinRoot(projectRoot, subDir, fieldName);
|
|
180
|
+
}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@actiondock/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "ActionDock Core Engine - Project loader, runtime execution, SQLite storage, standalone builder, and skill exporter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,21 +18,20 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
21
|
+
"node": ">=24.12.0"
|
|
22
22
|
},
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public",
|
|
25
25
|
"registry": "https://registry.npmjs.org/"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"build": "
|
|
29
|
-
"test": "
|
|
28
|
+
"build": "node ../../scripts/build.ts",
|
|
29
|
+
"test": "node ../../scripts/run-tests.ts"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@actiondock/sdk": "^2.
|
|
32
|
+
"@actiondock/sdk": "^2.2.1",
|
|
33
33
|
"ajv": "^8.17.1",
|
|
34
|
-
"ajv-formats": "^3.0.1"
|
|
35
|
-
"yaml": "^2.7.0"
|
|
34
|
+
"ajv-formats": "^3.0.1"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
37
|
"typescript": "^5.7.0"
|
package/dist/build/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./templates";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 构建时 Action 导入映射。
|
|
3
|
-
*/
|
|
4
|
-
export interface ActionImport {
|
|
5
|
-
/** Action 唯一标识符 */
|
|
6
|
-
id: string;
|
|
7
|
-
/** Action 源码文件物理路径 */
|
|
8
|
-
filePath: string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* 动态生成 Standalone 独立可执行文件的 TypeScript 入口文件源码。
|
|
12
|
-
*
|
|
13
|
-
* @param packageId 所属 Package ID
|
|
14
|
-
* @param version 版本号
|
|
15
|
-
* @param description 描述
|
|
16
|
-
* @param actions 待打包 Action 列表
|
|
17
|
-
* @param configDefs 声明的配置定义字典
|
|
18
|
-
*/
|
|
19
|
-
export declare function generateStandaloneEntrypoint(packageId: string, version: string, description: string | undefined, actions: ActionImport[], configDefs?: Record<string, unknown>): string;
|