@actiondock/core 2.5.1 → 2.7.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/dist/app/app.d.ts +14 -1
- package/dist/app/app.js +88 -222
- package/dist/app/static-index.d.ts +39 -0
- package/dist/app/static-index.js +164 -0
- package/dist/app/types.d.ts +5 -0
- package/dist/catalog/action-index.js +6 -4
- package/dist/catalog/package-catalog.js +2 -1
- package/dist/doctor/checks/index.d.ts +5 -0
- package/dist/doctor/checks/index.js +5 -0
- package/dist/doctor/checks/project-locate.d.ts +6 -0
- package/dist/doctor/checks/project-locate.js +36 -0
- package/dist/doctor/checks/project.d.ts +6 -0
- package/dist/doctor/checks/project.js +383 -0
- package/dist/doctor/checks/registry.d.ts +13 -0
- package/dist/doctor/checks/registry.js +207 -0
- package/dist/doctor/checks/runtime.d.ts +13 -0
- package/dist/doctor/checks/runtime.js +90 -0
- package/dist/doctor/checks/storage.d.ts +5 -0
- package/dist/doctor/checks/storage.js +34 -0
- package/dist/doctor/context.d.ts +35 -0
- package/dist/doctor/context.js +11 -0
- package/dist/doctor/doctor.d.ts +5 -0
- package/dist/doctor/doctor.js +33 -602
- package/dist/errors.d.ts +22 -0
- package/dist/errors.js +22 -0
- package/dist/execution/service.js +14 -9
- package/dist/export/templates.js +42 -30
- package/dist/host/host.d.ts +33 -0
- package/dist/host/host.js +222 -362
- package/dist/host/routing.d.ts +92 -0
- package/dist/host/routing.js +238 -0
- package/dist/host/types.d.ts +8 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/input/advice.d.ts +100 -0
- package/dist/input/advice.js +767 -0
- package/dist/input/describe.d.ts +106 -0
- package/dist/input/describe.js +176 -0
- package/dist/input/file-input.d.ts +54 -0
- package/dist/input/file-input.js +124 -0
- package/dist/input/flat-decode.d.ts +11 -0
- package/dist/input/flat-decode.js +13 -0
- package/dist/input/flat-errors.d.ts +72 -0
- package/dist/input/flat-errors.js +87 -0
- package/dist/input/flat-materializer.d.ts +29 -0
- package/dist/input/flat-materializer.js +179 -0
- package/dist/input/flat-parser.d.ts +50 -0
- package/dist/input/flat-parser.js +169 -0
- package/dist/input/flat-predicates.d.ts +34 -0
- package/dist/input/flat-predicates.js +50 -0
- package/dist/input/index.d.ts +14 -0
- package/dist/input/index.js +14 -0
- package/dist/input/input-resolver.d.ts +63 -0
- package/dist/input/input-resolver.js +254 -0
- package/dist/input/json-depth-scanner.d.ts +17 -0
- package/dist/input/json-depth-scanner.js +49 -0
- package/dist/input/metadata.d.ts +99 -0
- package/dist/input/metadata.js +99 -0
- package/dist/input/stdin-input.d.ts +26 -0
- package/dist/input/stdin-input.js +125 -0
- package/dist/input/utf8.d.ts +19 -0
- package/dist/input/utf8.js +36 -0
- package/dist/input/validation-mapper.d.ts +27 -0
- package/dist/input/validation-mapper.js +144 -0
- package/dist/ipc/host.js +38 -0
- package/dist/json/index.d.ts +1 -0
- package/dist/json/index.js +1 -0
- package/dist/json/value-validator.d.ts +88 -0
- package/dist/json/value-validator.js +330 -0
- package/dist/platform/types.d.ts +7 -0
- package/dist/process/control-arbiter.d.ts +107 -0
- package/dist/process/control-arbiter.js +251 -0
- package/dist/process/diagnostics-sink.d.ts +26 -0
- package/dist/process/diagnostics-sink.js +35 -0
- package/dist/process/index.d.ts +7 -0
- package/dist/process/index.js +7 -0
- package/dist/process/input-dispatcher.d.ts +88 -0
- package/dist/process/input-dispatcher.js +240 -0
- package/dist/process/managed-record.d.ts +78 -0
- package/dist/process/managed-record.js +1 -0
- package/dist/process/process-manager.d.ts +15 -56
- package/dist/process/process-manager.js +119 -707
- package/dist/process/reservation-table.d.ts +39 -0
- package/dist/process/reservation-table.js +80 -0
- package/dist/process/run-executor.d.ts +16 -0
- package/dist/process/run-executor.js +155 -0
- package/dist/process/terminal-output-cache.d.ts +66 -0
- package/dist/process/terminal-output-cache.js +132 -0
- package/dist/profile/client-actions.d.ts +56 -0
- package/dist/profile/client-actions.js +215 -0
- package/dist/profile/client-config.d.ts +20 -0
- package/dist/profile/client-config.js +51 -0
- package/dist/profile/client-health.d.ts +14 -0
- package/dist/profile/client-health.js +69 -0
- package/dist/profile/client-playbooks.d.ts +19 -0
- package/dist/profile/client-playbooks.js +36 -0
- package/dist/profile/client-query.d.ts +30 -0
- package/dist/profile/client-query.js +70 -0
- package/dist/profile/client-runs.d.ts +42 -0
- package/dist/profile/client-runs.js +58 -0
- package/dist/profile/client-state.d.ts +56 -0
- package/dist/profile/client-state.js +83 -0
- package/dist/profile/client-transport.d.ts +61 -0
- package/dist/profile/client-transport.js +156 -0
- package/dist/profile/client.d.ts +23 -142
- package/dist/profile/client.js +28 -588
- package/dist/profile/manager.js +1 -1
- package/dist/project/closure.d.ts +4 -4
- package/dist/project/closure.js +11 -5
- package/dist/project/init.js +2 -2
- package/dist/project/loader.d.ts +0 -25
- package/dist/project/loader.js +1 -154
- package/dist/project/transactions.d.ts +12 -14
- package/dist/project/transactions.js +60 -836
- package/dist/registry/registry.js +6 -4
- package/dist/registry/resolve.js +1 -1
- package/dist/runtime/action-registry.d.ts +45 -0
- package/dist/runtime/action-registry.js +108 -0
- package/dist/runtime/clock.d.ts +5 -17
- package/dist/runtime/clock.js +5 -15
- package/dist/runtime/context.d.ts +3 -0
- package/dist/runtime/context.js +17 -56
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.js +3 -0
- package/dist/runtime/package-runner-factory.d.ts +82 -0
- package/dist/runtime/package-runner-factory.js +186 -0
- package/dist/runtime/run-persistence.d.ts +85 -0
- package/dist/runtime/run-persistence.js +111 -0
- package/dist/runtime/runner.d.ts +25 -45
- package/dist/runtime/runner.js +130 -354
- package/dist/runtime/standalone.d.ts +25 -2
- package/dist/runtime/standalone.js +305 -87
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +1 -0
- package/dist/schema/validator.d.ts +10 -0
- package/dist/schema/validator.js +48 -54
- package/dist/server/dispatcher.d.ts +8 -3
- package/dist/server/dispatcher.js +16 -40
- package/dist/server/routes/runs.js +6 -4
- package/dist/server/security.d.ts +1 -7
- package/dist/server/security.js +2 -13
- package/dist/storage/clock.d.ts +25 -0
- package/dist/storage/clock.js +23 -0
- package/dist/storage/data-dir-lock.d.ts +3 -36
- package/dist/storage/data-dir-lock.js +48 -881
- package/dist/storage/index.d.ts +8 -1
- package/dist/storage/index.js +8 -2
- package/dist/storage/lazy.js +1 -0
- package/dist/storage/lock-core.d.ts +162 -0
- package/dist/storage/lock-core.js +885 -0
- package/dist/storage/sqlite.d.ts +19 -6
- package/dist/storage/sqlite.js +81 -89
- package/dist/storage/types.d.ts +27 -5
- package/dist/storage/types.js +21 -0
- package/dist/storage/utils.d.ts +22 -0
- package/dist/storage/utils.js +34 -0
- package/dist/target/local.d.ts +1 -0
- package/dist/target/local.js +23 -17
- package/dist/target/remote-errors.d.ts +21 -0
- package/dist/target/remote-errors.js +51 -0
- package/dist/target/remote-polling.d.ts +35 -0
- package/dist/target/remote-polling.js +104 -0
- package/dist/target/remote.d.ts +4 -0
- package/dist/target/remote.js +108 -301
- package/dist/target/sse-parser.d.ts +35 -0
- package/dist/target/sse-parser.js +163 -0
- package/dist/target/target.js +2 -0
- package/dist/target/types.d.ts +6 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/net.d.ts +10 -0
- package/dist/utils/net.js +16 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ActionRef, RuntimeError } from "@actiondock/sdk";
|
|
2
|
+
import type { ActionDockApp, ActionSpec, PackageInfo, PlaybookSpec, PlaybookSummary } from "../app/types.js";
|
|
3
|
+
import type { ActionPackageResolver } from "../project/resolver.js";
|
|
4
|
+
/**
|
|
5
|
+
* 判定异常是否为 not-found 语义(包内确实不存在该 Action)。
|
|
6
|
+
*
|
|
7
|
+
* 遍历匹配短标识符时仅跳过此类错误;存储损坏、模块加载失败等内部错误必须向调用方透传,
|
|
8
|
+
* 严禁被吞没后伪装成 ACTION_NOT_FOUND。
|
|
9
|
+
*/
|
|
10
|
+
export declare function isActionNotFoundLikeError(err: any): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 宽松解析引用:优先结构化解析,失败时按对象或裸短标识符回退。
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseRefLoose(ref: ActionRef | string): ActionRef;
|
|
15
|
+
/**
|
|
16
|
+
* 根调用可见性判定:非公开包且存在依赖解析器时,交由解析器委托规则裁决。
|
|
17
|
+
*/
|
|
18
|
+
export declare function isRootCallVisible(packageId: string, actionId: string, hostPublicPackageIds: ReadonlySet<string>, resolver?: ActionPackageResolver): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 跨包短标识符歧义消解结果:唯一匹配、歧义多匹配与零匹配三态。
|
|
21
|
+
*/
|
|
22
|
+
export type ShortRefResolution = {
|
|
23
|
+
kind: "unique";
|
|
24
|
+
app: ActionDockApp;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "ambiguous";
|
|
27
|
+
candidates: string[];
|
|
28
|
+
} | {
|
|
29
|
+
kind: "not_found";
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* 在全部已注册包中按短标识符解析唯一提供方。
|
|
33
|
+
*
|
|
34
|
+
* 可见性过滤遵循根调用规则(公开包直接可见;传递依赖包仅可见 Playbook 委托项);
|
|
35
|
+
* 仅 not-found 语义错误被跳过,其余异常向调用方透传。
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveShortRef(apps: readonly ActionDockApp[], actionId: string, visibility: {
|
|
38
|
+
hostPublicPackageIds: ReadonlySet<string>;
|
|
39
|
+
resolver?: ActionPackageResolver;
|
|
40
|
+
}): Promise<ShortRefResolution>;
|
|
41
|
+
/**
|
|
42
|
+
* 按包标识构造未找到错误信息:优先透传链接包加载失败的精准诊断。
|
|
43
|
+
*/
|
|
44
|
+
export declare function packageNotFoundMessage(packageId: string, failedLinkedPackages: ReadonlyMap<string, {
|
|
45
|
+
path: string;
|
|
46
|
+
error: string;
|
|
47
|
+
}>): string;
|
|
48
|
+
/**
|
|
49
|
+
* 静态查询并聚合可见包的 Playbook 规程摘要(带包前缀限定)。
|
|
50
|
+
*/
|
|
51
|
+
export declare function listVisiblePlaybooks(apps: readonly ActionDockApp[], visibility: {
|
|
52
|
+
hostPublicPackageIds: ReadonlySet<string>;
|
|
53
|
+
resolver?: ActionPackageResolver;
|
|
54
|
+
}): Promise<PlaybookSummary[]>;
|
|
55
|
+
/**
|
|
56
|
+
* 静态查询指定 Playbook 规范:支持「包/规程」限定引用与裸短标识符两级解析。
|
|
57
|
+
* 未声明依赖的传递包、不存在的规程与空匹配分别抛出对应语义错误。
|
|
58
|
+
*/
|
|
59
|
+
export declare function describeVisiblePlaybook(apps: readonly ActionDockApp[], id: string, visibility: {
|
|
60
|
+
hostPublicPackageIds: ReadonlySet<string>;
|
|
61
|
+
resolver?: ActionPackageResolver;
|
|
62
|
+
}): Promise<PlaybookSpec>;
|
|
63
|
+
/**
|
|
64
|
+
* 聚合全部已注册包的元数据信息。
|
|
65
|
+
*/
|
|
66
|
+
export declare function collectPackageInfos(apps: readonly ActionDockApp[]): Promise<PackageInfo[]>;
|
|
67
|
+
/**
|
|
68
|
+
* 构造失配类错误响应载荷(ACTION_NOT_FOUND / AMBIGUOUS_ACTION_REF 等)。
|
|
69
|
+
*/
|
|
70
|
+
export declare function buildRuntimeError(code: string, message: string, details?: Record<string, unknown>): RuntimeError;
|
|
71
|
+
/**
|
|
72
|
+
* 构造短标识符歧义错误消息(供静态查询与启动执行链路复用统一文案)。
|
|
73
|
+
*/
|
|
74
|
+
export declare function ambiguousActionMessage(actionId: string, candidates: readonly string[]): string;
|
|
75
|
+
/**
|
|
76
|
+
* 静态查询指定 Action 规范:包限定引用直查,裸短标识符跨包消歧后返回。
|
|
77
|
+
*/
|
|
78
|
+
export declare function describeActionAcrossApps(ref: ActionRef | string, apps: readonly ActionDockApp[], visibility: {
|
|
79
|
+
hostPublicPackageIds: ReadonlySet<string>;
|
|
80
|
+
resolver?: ActionPackageResolver;
|
|
81
|
+
}, failedLinkedPackages: ReadonlyMap<string, {
|
|
82
|
+
path: string;
|
|
83
|
+
error: string;
|
|
84
|
+
}>): Promise<ActionSpec>;
|
|
85
|
+
/** existsSync 的可注入探测依赖(纯函数模块保持可测试性) */
|
|
86
|
+
export type ExistsProbe = (path: string) => boolean;
|
|
87
|
+
/**
|
|
88
|
+
* 解析宿主自动加载工程根目录:显式指定优先,其次当前进程工作目录探测。
|
|
89
|
+
*/
|
|
90
|
+
export declare function resolveProjectRoot(options: {
|
|
91
|
+
projectRoot?: string;
|
|
92
|
+
}, detect: () => string | null, exists?: ExistsProbe): string | null;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { ActionResolver } from "../catalog/action-resolver.js";
|
|
3
|
+
/**
|
|
4
|
+
* 判定异常是否为 not-found 语义(包内确实不存在该 Action)。
|
|
5
|
+
*
|
|
6
|
+
* 遍历匹配短标识符时仅跳过此类错误;存储损坏、模块加载失败等内部错误必须向调用方透传,
|
|
7
|
+
* 严禁被吞没后伪装成 ACTION_NOT_FOUND。
|
|
8
|
+
*/
|
|
9
|
+
export function isActionNotFoundLikeError(err) {
|
|
10
|
+
if (!err) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (err.code === "ACTION_NOT_FOUND" || err.code === "NOT_FOUND") {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
const message = typeof err.message === "string" ? err.message : String(err);
|
|
17
|
+
return (message.startsWith("ACTION_NOT_FOUND:") ||
|
|
18
|
+
/Action '[^']*' not found in package/.test(message));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 宽松解析引用:优先结构化解析,失败时按对象或裸短标识符回退。
|
|
22
|
+
*/
|
|
23
|
+
export function parseRefLoose(ref) {
|
|
24
|
+
try {
|
|
25
|
+
return ActionResolver.parseRef(ref);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return typeof ref === "object" ? ref : { actionId: ref };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 根调用可见性判定:非公开包且存在依赖解析器时,交由解析器委托规则裁决。
|
|
33
|
+
*/
|
|
34
|
+
export function isRootCallVisible(packageId, actionId, hostPublicPackageIds, resolver) {
|
|
35
|
+
const isPublic = hostPublicPackageIds.has(packageId);
|
|
36
|
+
if (isPublic) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (resolver && !resolver.canRootCall(packageId, actionId)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 在全部已注册包中按短标识符解析唯一提供方。
|
|
46
|
+
*
|
|
47
|
+
* 可见性过滤遵循根调用规则(公开包直接可见;传递依赖包仅可见 Playbook 委托项);
|
|
48
|
+
* 仅 not-found 语义错误被跳过,其余异常向调用方透传。
|
|
49
|
+
*/
|
|
50
|
+
export async function resolveShortRef(apps, actionId, visibility) {
|
|
51
|
+
const matches = [];
|
|
52
|
+
for (const app of apps) {
|
|
53
|
+
try {
|
|
54
|
+
if (!isRootCallVisible(app.packageId, actionId, visibility.hostPublicPackageIds, visibility.resolver)) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
await app.describeAction(actionId);
|
|
58
|
+
matches.push(app);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
// 仅将 not-found 语义视为「包内无此 Action」;其余异常必须透传,避免内部错误伪装成 ACTION_NOT_FOUND
|
|
62
|
+
if (!isActionNotFoundLikeError(err)) {
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (matches.length === 1) {
|
|
68
|
+
return { kind: "unique", app: matches[0] };
|
|
69
|
+
}
|
|
70
|
+
if (matches.length > 1) {
|
|
71
|
+
return { kind: "ambiguous", candidates: matches.map((m) => m.packageId) };
|
|
72
|
+
}
|
|
73
|
+
return { kind: "not_found" };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 按包标识构造未找到错误信息:优先透传链接包加载失败的精准诊断。
|
|
77
|
+
*/
|
|
78
|
+
export function packageNotFoundMessage(packageId, failedLinkedPackages) {
|
|
79
|
+
const failed = failedLinkedPackages.get(packageId);
|
|
80
|
+
if (failed) {
|
|
81
|
+
return `Package '${packageId}' not found in host (failed to load from '${failed.path}': ${failed.error})`;
|
|
82
|
+
}
|
|
83
|
+
return `Package '${packageId}' not found in host`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 静态查询并聚合可见包的 Playbook 规程摘要(带包前缀限定)。
|
|
87
|
+
*/
|
|
88
|
+
export async function listVisiblePlaybooks(apps, visibility) {
|
|
89
|
+
const results = [];
|
|
90
|
+
for (const app of apps) {
|
|
91
|
+
const isPublic = visibility.hostPublicPackageIds.has(app.packageId);
|
|
92
|
+
if (!isPublic && visibility.resolver) {
|
|
93
|
+
const graph = visibility.resolver.resolveSync();
|
|
94
|
+
if (!graph.directDependencyIds.has(app.packageId)) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const appPlaybooks = await app.listPlaybooks();
|
|
99
|
+
for (const item of appPlaybooks) {
|
|
100
|
+
const qualifiedId = apps.length > 1 && !item.id.includes("/")
|
|
101
|
+
? `${app.packageId}/${item.id}`
|
|
102
|
+
: item.id;
|
|
103
|
+
results.push({
|
|
104
|
+
...item,
|
|
105
|
+
id: qualifiedId,
|
|
106
|
+
packageId: app.packageId,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return results;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 静态查询指定 Playbook 规范:支持「包/规程」限定引用与裸短标识符两级解析。
|
|
114
|
+
* 未声明依赖的传递包、不存在的规程与空匹配分别抛出对应语义错误。
|
|
115
|
+
*/
|
|
116
|
+
export async function describeVisiblePlaybook(apps, id, visibility) {
|
|
117
|
+
if (id.includes("/")) {
|
|
118
|
+
const lastSlashIndex = id.lastIndexOf("/");
|
|
119
|
+
const packageId = id.slice(0, lastSlashIndex);
|
|
120
|
+
const playbookId = id.slice(lastSlashIndex + 1);
|
|
121
|
+
const isPublic = visibility.hostPublicPackageIds.has(packageId);
|
|
122
|
+
if (!isPublic && visibility.resolver) {
|
|
123
|
+
const graph = visibility.resolver.resolveSync();
|
|
124
|
+
if (!graph.directDependencyIds.has(packageId)) {
|
|
125
|
+
throw new Error(`UNDECLARED_ACTION_DEPENDENCY: Playbook '${id}' belongs to undeclared transitive package '${packageId}'`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const app = apps.find((a) => a.packageId === packageId);
|
|
129
|
+
if (!app) {
|
|
130
|
+
throw new Error(`Package '${packageId}' not found in host`);
|
|
131
|
+
}
|
|
132
|
+
return app.describePlaybook(playbookId);
|
|
133
|
+
}
|
|
134
|
+
for (const app of apps) {
|
|
135
|
+
try {
|
|
136
|
+
const isPublic = visibility.hostPublicPackageIds.has(app.packageId);
|
|
137
|
+
if (!isPublic && visibility.resolver) {
|
|
138
|
+
const graph = visibility.resolver.resolveSync();
|
|
139
|
+
if (!graph.directDependencyIds.has(app.packageId)) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return await app.describePlaybook(id);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// 忽略未匹配的包
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
throw new Error(`Playbook '${id}' not found in any registered package`);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 聚合全部已注册包的元数据信息。
|
|
153
|
+
*/
|
|
154
|
+
export async function collectPackageInfos(apps) {
|
|
155
|
+
return Promise.all(apps.map((app) => app.info()));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 构造失配类错误响应载荷(ACTION_NOT_FOUND / AMBIGUOUS_ACTION_REF 等)。
|
|
159
|
+
*/
|
|
160
|
+
export function buildRuntimeError(code, message, details) {
|
|
161
|
+
const error = { code, message };
|
|
162
|
+
if (details !== undefined) {
|
|
163
|
+
error.details = details;
|
|
164
|
+
}
|
|
165
|
+
return error;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 构造短标识符歧义错误消息(供静态查询与启动执行链路复用统一文案)。
|
|
169
|
+
*/
|
|
170
|
+
export function ambiguousActionMessage(actionId, candidates) {
|
|
171
|
+
const joined = candidates.map((c) => `${c}/${actionId}`).join(", ");
|
|
172
|
+
return `Action '${actionId}' is ambiguous and provided by multiple packages: ${joined}. Please specify '<package-id>/${actionId}'.`;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 静态查询指定 Action 规范:包限定引用直查,裸短标识符跨包消歧后返回。
|
|
176
|
+
*/
|
|
177
|
+
export async function describeActionAcrossApps(ref, apps, visibility, failedLinkedPackages) {
|
|
178
|
+
const parsed = parseRefLoose(ref);
|
|
179
|
+
if (parsed.packageId) {
|
|
180
|
+
if (!isRootCallVisible(parsed.packageId, parsed.actionId, visibility.hostPublicPackageIds, visibility.resolver)) {
|
|
181
|
+
throw new Error(`UNDECLARED_ACTION_DEPENDENCY: Action '${parsed.packageId}/${parsed.actionId}' is not declared as a direct dependency in actiondock.json and is not delegated by a visible playbook`);
|
|
182
|
+
}
|
|
183
|
+
const app = apps.find((a) => a.packageId === parsed.packageId);
|
|
184
|
+
if (!app) {
|
|
185
|
+
throw new Error(packageNotFoundMessage(parsed.packageId, failedLinkedPackages));
|
|
186
|
+
}
|
|
187
|
+
const spec = await app.describeAction(parsed.actionId);
|
|
188
|
+
return {
|
|
189
|
+
...spec,
|
|
190
|
+
packageId: app.packageId,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const matches = [];
|
|
194
|
+
for (const app of apps) {
|
|
195
|
+
try {
|
|
196
|
+
if (!isRootCallVisible(app.packageId, parsed.actionId, visibility.hostPublicPackageIds, visibility.resolver)) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const spec = await app.describeAction(parsed.actionId);
|
|
200
|
+
matches.push({ app, spec: { ...spec, packageId: app.packageId } });
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
// 仅将 not-found 语义视为「包内无此 Action」;其余异常必须透传,避免内部错误伪装成 ACTION_NOT_FOUND
|
|
204
|
+
if (!isActionNotFoundLikeError(err)) {
|
|
205
|
+
throw err;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (matches.length === 1) {
|
|
210
|
+
return {
|
|
211
|
+
...matches[0].spec,
|
|
212
|
+
packageId: matches[0].app.packageId,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
if (matches.length > 1) {
|
|
216
|
+
const err = new Error(`INVALID_ACTION_REF: ${ambiguousActionMessage(parsed.actionId, matches.map((m) => m.app.packageId))} (AMBIGUOUS_ACTION_REF)`);
|
|
217
|
+
err.code = "INVALID_ACTION_REF";
|
|
218
|
+
err.details = { alias: "AMBIGUOUS_ACTION_REF", candidates: matches.map((m) => m.app.packageId) };
|
|
219
|
+
throw err;
|
|
220
|
+
}
|
|
221
|
+
throw new Error(`ACTION_NOT_FOUND: Action '${parsed.actionId}' not found in any registered package`);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 解析宿主自动加载工程根目录:显式指定优先,其次当前进程工作目录探测。
|
|
225
|
+
*/
|
|
226
|
+
export function resolveProjectRoot(options, detect, exists = existsSync) {
|
|
227
|
+
let root = options.projectRoot;
|
|
228
|
+
if (!root) {
|
|
229
|
+
const detected = detect();
|
|
230
|
+
if (detected) {
|
|
231
|
+
root = detected;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!root || !exists(root)) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
return root;
|
|
238
|
+
}
|
package/dist/host/types.d.ts
CHANGED
|
@@ -16,6 +16,12 @@ export interface ActionDockHostOptions {
|
|
|
16
16
|
autoLoadCurrentProject?: boolean;
|
|
17
17
|
/** 是否扫描已软链接的外部包(通过 listLinkedPackages,默认为 false) */
|
|
18
18
|
scanLinkedPackages?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 是否以数据目录持有者身份打开包存储:true 时内部创建的 App 存储在打开阶段
|
|
21
|
+
* 收割遗留非终态运行记录。默认 true(Host 本身即持有者);
|
|
22
|
+
* CLI 查询命令创建旁观 Host 时显式置 false,避免误收割并发 serve 进程的在途运行。
|
|
23
|
+
*/
|
|
24
|
+
recoverOrphans?: boolean;
|
|
19
25
|
/** 显式注入的运行时平台适配 */
|
|
20
26
|
platform?: RuntimePlatform;
|
|
21
27
|
/** 全局最大并发活跃运行数 */
|
|
@@ -44,6 +50,8 @@ export interface ActionDockHostOptions {
|
|
|
44
50
|
* 作为多包环境下的全局协调中枢,负责多包生命周期、完全限定引用路由、依赖校验与配额管理。
|
|
45
51
|
*/
|
|
46
52
|
export interface ActionDockHost {
|
|
53
|
+
/** 宿主容器初始化配置项(只读) */
|
|
54
|
+
readonly options?: ActionDockHostOptions;
|
|
47
55
|
/** 获取所有已注册包的元数据信息列表 */
|
|
48
56
|
info(): Promise<PackageInfo[]>;
|
|
49
57
|
/** 静态列出所有已注册包中可用的 Action 摘要 */
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export * from "./profile/index.js";
|
|
|
9
9
|
export * from "./project/index.js";
|
|
10
10
|
export * from "./registry/index.js";
|
|
11
11
|
export * from "./runtime/index.js";
|
|
12
|
-
export * from "./schema/
|
|
12
|
+
export * from "./schema/index.js";
|
|
13
13
|
export * from "./server/index.js";
|
|
14
14
|
export * from "./storage/index.js";
|
|
15
15
|
export * from "./utils/index.js";
|
|
@@ -19,4 +19,6 @@ export * from "./host/index.js";
|
|
|
19
19
|
export * from "./target/index.js";
|
|
20
20
|
export * from "./ipc/index.js";
|
|
21
21
|
export * from "./process/index.js";
|
|
22
|
+
export * from "./input/index.js";
|
|
23
|
+
export * from "./json/index.js";
|
|
22
24
|
export type { ModuleLoader } from "./runtime/index.js";
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export * from "./profile/index.js";
|
|
|
9
9
|
export * from "./project/index.js";
|
|
10
10
|
export * from "./registry/index.js";
|
|
11
11
|
export * from "./runtime/index.js";
|
|
12
|
-
export * from "./schema/
|
|
12
|
+
export * from "./schema/index.js";
|
|
13
13
|
export * from "./server/index.js";
|
|
14
14
|
export * from "./storage/index.js";
|
|
15
15
|
export * from "./utils/index.js";
|
|
@@ -19,3 +19,5 @@ export * from "./host/index.js";
|
|
|
19
19
|
export * from "./target/index.js";
|
|
20
20
|
export * from "./ipc/index.js";
|
|
21
21
|
export * from "./process/index.js";
|
|
22
|
+
export * from "./input/index.js";
|
|
23
|
+
export * from "./json/index.js";
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 单个字段的输入建议明细(v1 机器契约)。
|
|
3
|
+
*/
|
|
4
|
+
export interface CliInputFieldAdviceV1 {
|
|
5
|
+
/** 字段路径(属性名) */
|
|
6
|
+
path: string;
|
|
7
|
+
/** 是否允许作为输入传入 */
|
|
8
|
+
inputAllowed: boolean;
|
|
9
|
+
/** 是否可通过扁平语法安全赋值 */
|
|
10
|
+
flatSafe: boolean;
|
|
11
|
+
/** 是否为必填字段 */
|
|
12
|
+
required?: boolean;
|
|
13
|
+
/** 字段模式类型 */
|
|
14
|
+
type?: string;
|
|
15
|
+
/** 赋值操作符("=" 或 ":=") */
|
|
16
|
+
operator?: "=" | ":=";
|
|
17
|
+
/** 编码类型标识 */
|
|
18
|
+
encoding?: "string" | "json-number" | "json-boolean" | "json-null" | "json-array" | "json-object" | "json" | string;
|
|
19
|
+
/** 赋值模板样例 */
|
|
20
|
+
assignmentTemplate?: string;
|
|
21
|
+
/** 无法通过扁平赋值或被禁止的原因代码 */
|
|
22
|
+
reason?: "FORBIDDEN_PROPERTY" | "UNSAFE_FLAT_PROPERTY" | "PROPERTY_SCHEMA_FALSE" | string;
|
|
23
|
+
/** 推荐的降级输入通道 */
|
|
24
|
+
fallback?: "stdin-json" | null;
|
|
25
|
+
/** 字段描述信息 */
|
|
26
|
+
description?: string;
|
|
27
|
+
/** 人类提示信息 */
|
|
28
|
+
hint?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Action 输入模式编码顾问分析报告(v1 机器契约)。
|
|
32
|
+
*/
|
|
33
|
+
export interface CliInputAdviceV1 {
|
|
34
|
+
version: 1;
|
|
35
|
+
analysisMode: "declared-properties-only";
|
|
36
|
+
analysisStatus: "ok" | "unsupported" | "malformed";
|
|
37
|
+
analysisCode?: "MALFORMED_SCHEMA" | "COMPLEX_SCHEMA" | "UNSUPPORTED_SCHEMA_SHAPE";
|
|
38
|
+
analysisMessage?: string;
|
|
39
|
+
schemaState: "absent" | "reject-all" | "any" | "object" | "json-only" | "complex";
|
|
40
|
+
inputFeasibility: "known-impossible" | "possible-or-unknown";
|
|
41
|
+
flatAvailable: boolean;
|
|
42
|
+
requiredSatisfiable: boolean | null;
|
|
43
|
+
flatCandidate: boolean;
|
|
44
|
+
schemaRecommendedMode: "none" | "flat" | "full-json";
|
|
45
|
+
feasibilityCode?: "SCHEMA_REJECTS_ALL" | "REQUIRED_FIELD_FORBIDDEN" | "REQUIRED_FIELD_REJECTS_ALL" | "REQUIRED_FIELD_DISALLOWED_BY_ADDITIONAL_PROPERTIES";
|
|
46
|
+
fields: CliInputFieldAdviceV1[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 依据 inputSchema 构造 v1 版本的 Action 输入编码顾问报告(机器契约)。
|
|
50
|
+
*
|
|
51
|
+
* @param schema Action 的 inputSchema 定义
|
|
52
|
+
* @returns 遵循技术设计文档规范的结构化输入建议
|
|
53
|
+
*/
|
|
54
|
+
export declare function buildCliInputAdviceV1(schema: unknown): CliInputAdviceV1;
|
|
55
|
+
export declare const FLAT_SAFE_KEY_REGEX: RegExp;
|
|
56
|
+
export declare const FLAT_ENCODING_GUIDELINES: readonly string[];
|
|
57
|
+
/**
|
|
58
|
+
* 单个字段的输入建议明细。
|
|
59
|
+
*/
|
|
60
|
+
export interface ActionInputFieldAdvice {
|
|
61
|
+
/** 字段路径(属性名) */
|
|
62
|
+
path: string;
|
|
63
|
+
/** 字段类型字符串 */
|
|
64
|
+
type: string;
|
|
65
|
+
/** 是否为必填字段 */
|
|
66
|
+
required: boolean;
|
|
67
|
+
/** 字段名是否满足扁平编码安全规范 */
|
|
68
|
+
flatSafe: boolean;
|
|
69
|
+
/** 编码模板(如 "name=TEXT"、"age:=NUMBER"、"meta:=JSON"),非直接可执行 token */
|
|
70
|
+
assignmentTemplate?: string;
|
|
71
|
+
/** 人类说明文字,如 "大型结构建议使用 --input-file" */
|
|
72
|
+
hint?: string;
|
|
73
|
+
/** 字段描述信息 */
|
|
74
|
+
description?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Action 输入模式整体编码顾问分析报告。
|
|
78
|
+
*/
|
|
79
|
+
export interface ActionInputAdvice {
|
|
80
|
+
/** 根模式是否支持扁平入参赋值(仅当根模式为对象且所有 required 字段均具备 flatSafe 赋值方案时为 true) */
|
|
81
|
+
flatSupported: boolean;
|
|
82
|
+
/** 是否存在至少一个可扁平化的字段 */
|
|
83
|
+
hasFlatFields: boolean;
|
|
84
|
+
/** 字段明细清单 */
|
|
85
|
+
fields: ActionInputFieldAdvice[];
|
|
86
|
+
/** 所有必填字段的编码模板数组 */
|
|
87
|
+
requiredTemplates: string[];
|
|
88
|
+
/** 可选字段的编码模板数组 */
|
|
89
|
+
optionalTemplates: string[];
|
|
90
|
+
/** 结构化提示与降级说明清单 */
|
|
91
|
+
notes: string[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 依据 inputSchema 构造统一的 Action 输入编码建议。
|
|
95
|
+
*
|
|
96
|
+
* @param schema Action 的 inputSchema 定义
|
|
97
|
+
* @returns 结构化编码建议报告
|
|
98
|
+
*/
|
|
99
|
+
export declare function buildActionInputAdvice(schema: unknown): ActionInputAdvice;
|
|
100
|
+
export { formatActionDetail } from "./describe.js";
|