@actiondock/core 2.7.0 → 2.8.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.
Files changed (236) hide show
  1. package/README.md +61 -68
  2. package/dist/catalog/action-catalog.d.ts +56 -0
  3. package/dist/catalog/action-catalog.js +202 -0
  4. package/dist/catalog/discovery.d.ts +60 -0
  5. package/dist/catalog/discovery.js +119 -0
  6. package/dist/catalog/graph.d.ts +190 -0
  7. package/dist/catalog/graph.js +589 -0
  8. package/dist/catalog/index.d.ts +5 -5
  9. package/dist/catalog/index.js +5 -5
  10. package/dist/catalog/resolve-action.d.ts +43 -0
  11. package/dist/catalog/resolve-action.js +119 -0
  12. package/dist/catalog/resolve-playbook.d.ts +26 -0
  13. package/dist/catalog/resolve-playbook.js +114 -0
  14. package/dist/doctor/checks/project.js +27 -8
  15. package/dist/doctor/checks/registry.js +2 -2
  16. package/dist/doctor/checks/runtime.js +34 -1
  17. package/dist/errors.d.ts +102 -10
  18. package/dist/errors.js +103 -10
  19. package/dist/execution/service.d.ts +18 -16
  20. package/dist/execution/service.js +183 -252
  21. package/dist/execution/types.d.ts +25 -69
  22. package/dist/execution/types.js +2 -1
  23. package/dist/filter/intent.d.ts +8 -9
  24. package/dist/filter/intent.js +49 -10
  25. package/dist/graph/index.d.ts +4 -0
  26. package/dist/graph/index.js +4 -0
  27. package/dist/host/host.d.ts +74 -32
  28. package/dist/host/host.js +585 -336
  29. package/dist/host/routing.d.ts +15 -48
  30. package/dist/host/routing.js +90 -153
  31. package/dist/host/types.d.ts +50 -17
  32. package/dist/index.d.ts +21 -24
  33. package/dist/index.js +19 -23
  34. package/dist/input/advice.d.ts +5 -1
  35. package/dist/input/advice.js +163 -214
  36. package/dist/input/describe.d.ts +1 -1
  37. package/dist/input/flat-errors.d.ts +5 -6
  38. package/dist/input/flat-errors.js +6 -6
  39. package/dist/input/flat-materializer.js +42 -44
  40. package/dist/invocation/index.d.ts +2 -0
  41. package/dist/invocation/index.js +2 -0
  42. package/dist/invocation/policy.d.ts +157 -0
  43. package/dist/invocation/policy.js +231 -0
  44. package/dist/invocation/types.d.ts +172 -0
  45. package/dist/invocation/types.js +97 -0
  46. package/dist/ipc/diagnostic.d.ts +0 -12
  47. package/dist/ipc/diagnostic.js +0 -21
  48. package/dist/ipc/host.d.ts +4 -4
  49. package/dist/ipc/host.js +44 -47
  50. package/dist/ipc/index.d.ts +1 -1
  51. package/dist/ipc/index.js +1 -1
  52. package/dist/ipc/service.d.ts +40 -0
  53. package/dist/ipc/service.js +349 -0
  54. package/dist/ipc/types.d.ts +21 -15
  55. package/dist/node/index.d.ts +1 -0
  56. package/dist/node/index.js +1 -0
  57. package/dist/node/module-loader.d.ts +63 -0
  58. package/dist/node/module-loader.js +112 -0
  59. package/dist/package/index.d.ts +23 -0
  60. package/dist/package/index.js +18 -0
  61. package/dist/{app/app.d.ts → package/runtime.d.ts} +41 -20
  62. package/dist/{app/app.js → package/runtime.js} +140 -95
  63. package/dist/{app → package}/static-index.js +58 -41
  64. package/dist/package/storage-view.d.ts +13 -0
  65. package/dist/package/storage-view.js +22 -0
  66. package/dist/{app → package}/types.d.ts +76 -57
  67. package/dist/package/types.js +22 -0
  68. package/dist/platform/index.d.ts +1 -1
  69. package/dist/platform/index.js +1 -1
  70. package/dist/platform/node.d.ts +48 -0
  71. package/dist/platform/node.js +96 -0
  72. package/dist/platform/types.d.ts +0 -9
  73. package/dist/process/control-arbiter.d.ts +2 -1
  74. package/dist/process/control-arbiter.js +1 -2
  75. package/dist/process/driver.d.ts +9 -8
  76. package/dist/process/driver.js +11 -22
  77. package/dist/process/index.d.ts +2 -0
  78. package/dist/process/index.js +2 -0
  79. package/dist/process/managed-record.d.ts +2 -2
  80. package/dist/process/process-driver.d.ts +109 -0
  81. package/dist/process/process-driver.js +650 -0
  82. package/dist/process/process-executor.d.ts +47 -0
  83. package/dist/process/process-executor.js +296 -0
  84. package/dist/process/process-manager.js +48 -26
  85. package/dist/process/run-executor.js +12 -12
  86. package/dist/profile/client-actions.js +2 -2
  87. package/dist/profile/client-health.js +2 -2
  88. package/dist/profile/client-query.js +5 -6
  89. package/dist/profile/client-transport.d.ts +19 -17
  90. package/dist/profile/client-transport.js +47 -80
  91. package/dist/profile/client.d.ts +2 -2
  92. package/dist/profile/client.js +1 -1
  93. package/dist/profile/index.d.ts +1 -0
  94. package/dist/profile/index.js +1 -0
  95. package/dist/profile/manager.d.ts +5 -0
  96. package/dist/profile/manager.js +41 -6
  97. package/dist/project/closure.js +2 -2
  98. package/dist/project/index.d.ts +8 -1
  99. package/dist/project/index.js +10 -1
  100. package/dist/project/init.js +2 -2
  101. package/dist/project/loader.d.ts +1 -1
  102. package/dist/project/loader.js +26 -29
  103. package/dist/project/transactions.js +5 -10
  104. package/dist/registry/index.d.ts +3 -1
  105. package/dist/registry/index.js +2 -1
  106. package/dist/registry/lock.d.ts +28 -7
  107. package/dist/registry/lock.js +136 -16
  108. package/dist/registry/registry.d.ts +1 -5
  109. package/dist/registry/registry.js +1 -53
  110. package/dist/registry/scan.d.ts +0 -15
  111. package/dist/registry/scan.js +0 -59
  112. package/dist/registry/store.d.ts +42 -0
  113. package/dist/registry/store.js +43 -0
  114. package/dist/registry/types.d.ts +0 -24
  115. package/dist/runtime/action-collection.d.ts +1 -1
  116. package/dist/runtime/action-registry.d.ts +0 -4
  117. package/dist/runtime/action-registry.js +0 -7
  118. package/dist/runtime/context.js +5 -11
  119. package/dist/runtime/events.js +3 -6
  120. package/dist/runtime/identity.d.ts +22 -0
  121. package/dist/runtime/identity.js +10 -0
  122. package/dist/runtime/index.d.ts +1 -2
  123. package/dist/runtime/index.js +1 -2
  124. package/dist/runtime/module-loader.d.ts +2 -34
  125. package/dist/runtime/module-loader.js +1 -16
  126. package/dist/runtime/process.d.ts +6 -24
  127. package/dist/runtime/process.js +1 -118
  128. package/dist/runtime/run-persistence.js +2 -5
  129. package/dist/runtime/runner.d.ts +33 -93
  130. package/dist/runtime/runner.js +132 -364
  131. package/dist/runtime/standalone.d.ts +23 -8
  132. package/dist/runtime/standalone.js +100 -147
  133. package/dist/server/body.d.ts +16 -8
  134. package/dist/server/body.js +33 -16
  135. package/dist/server/dispatcher.d.ts +6 -10
  136. package/dist/server/dispatcher.js +24 -32
  137. package/dist/server/http-server.d.ts +87 -0
  138. package/dist/server/http-server.js +304 -0
  139. package/dist/server/index.d.ts +11 -0
  140. package/dist/server/index.js +10 -0
  141. package/dist/server/mcp-endpoint.d.ts +61 -0
  142. package/dist/server/mcp-endpoint.js +118 -0
  143. package/dist/server/routes/actions.js +34 -28
  144. package/dist/server/routes/common.d.ts +10 -14
  145. package/dist/server/routes/common.js +32 -56
  146. package/dist/server/routes/config.js +54 -64
  147. package/dist/server/routes/doctor.d.ts +1 -1
  148. package/dist/server/routes/doctor.js +10 -18
  149. package/dist/server/routes/health.d.ts +1 -1
  150. package/dist/server/routes/health.js +2 -3
  151. package/dist/server/routes/info.d.ts +2 -2
  152. package/dist/server/routes/info.js +12 -13
  153. package/dist/server/routes/playbooks.js +16 -29
  154. package/dist/server/routes/runs.js +95 -117
  155. package/dist/server/routes/state.js +63 -62
  156. package/dist/server/server.d.ts +2 -2
  157. package/dist/server/server.js +43 -227
  158. package/dist/server/types.d.ts +8 -19
  159. package/dist/service/factory.d.ts +12 -0
  160. package/dist/service/factory.js +85 -0
  161. package/dist/{target → service}/index.d.ts +1 -1
  162. package/dist/{target → service}/index.js +1 -1
  163. package/dist/service/local.d.ts +27 -0
  164. package/dist/service/local.js +138 -0
  165. package/dist/{target → service}/remote-errors.d.ts +3 -6
  166. package/dist/service/remote-errors.js +38 -0
  167. package/dist/{target → service}/remote-polling.d.ts +2 -2
  168. package/dist/{target → service}/remote-polling.js +8 -8
  169. package/dist/service/remote.d.ts +34 -0
  170. package/dist/service/remote.js +634 -0
  171. package/dist/service/sse-stream.d.ts +24 -0
  172. package/dist/service/sse-stream.js +139 -0
  173. package/dist/service/types.d.ts +272 -0
  174. package/dist/service/types.js +32 -0
  175. package/dist/storage/data-dir-lock.js +10 -5
  176. package/dist/storage/driver.d.ts +2 -1
  177. package/dist/storage/driver.js +3 -52
  178. package/dist/storage/index.d.ts +1 -0
  179. package/dist/storage/index.js +1 -0
  180. package/dist/storage/lock-core.d.ts +2 -6
  181. package/dist/storage/lock-core.js +4 -17
  182. package/dist/storage/params.d.ts +2 -8
  183. package/dist/storage/params.js +2 -8
  184. package/dist/storage/sqlite-driver.d.ts +40 -0
  185. package/dist/storage/sqlite-driver.js +116 -0
  186. package/dist/storage/sqlite.js +21 -6
  187. package/dist/storage/types.d.ts +4 -4
  188. package/dist/storage/types.js +2 -2
  189. package/dist/utils/index.d.ts +53 -0
  190. package/dist/utils/index.js +99 -4
  191. package/dist/utils/process.d.ts +10 -0
  192. package/dist/utils/process.js +21 -0
  193. package/dist/version.d.ts +1 -1
  194. package/dist/version.js +1 -1
  195. package/package.json +41 -3
  196. package/dist/app/index.d.ts +0 -2
  197. package/dist/app/index.js +0 -2
  198. package/dist/app/types.js +0 -1
  199. package/dist/catalog/action-index.d.ts +0 -9
  200. package/dist/catalog/action-index.js +0 -95
  201. package/dist/catalog/action-resolver.d.ts +0 -20
  202. package/dist/catalog/action-resolver.js +0 -95
  203. package/dist/catalog/location-registry.d.ts +0 -15
  204. package/dist/catalog/location-registry.js +0 -138
  205. package/dist/catalog/package-catalog.d.ts +0 -7
  206. package/dist/catalog/package-catalog.js +0 -77
  207. package/dist/catalog/types.d.ts +0 -68
  208. package/dist/catalog/types.js +0 -1
  209. package/dist/export/index.d.ts +0 -1
  210. package/dist/export/index.js +0 -1
  211. package/dist/export/templates.d.ts +0 -71
  212. package/dist/export/templates.js +0 -635
  213. package/dist/ipc/target.d.ts +0 -74
  214. package/dist/ipc/target.js +0 -365
  215. package/dist/platform/default.d.ts +0 -38
  216. package/dist/platform/default.js +0 -78
  217. package/dist/project/resolver.d.ts +0 -116
  218. package/dist/project/resolver.js +0 -376
  219. package/dist/registry/resolve.d.ts +0 -62
  220. package/dist/registry/resolve.js +0 -195
  221. package/dist/runtime/execution-manager.d.ts +0 -48
  222. package/dist/runtime/execution-manager.js +0 -66
  223. package/dist/runtime/package-runner-factory.d.ts +0 -82
  224. package/dist/runtime/package-runner-factory.js +0 -186
  225. package/dist/target/local.d.ts +0 -53
  226. package/dist/target/local.js +0 -349
  227. package/dist/target/remote-errors.js +0 -51
  228. package/dist/target/remote.d.ts +0 -86
  229. package/dist/target/remote.js +0 -818
  230. package/dist/target/target.d.ts +0 -6
  231. package/dist/target/target.js +0 -37
  232. package/dist/target/types.d.ts +0 -261
  233. package/dist/target/types.js +0 -35
  234. /package/dist/{app → package}/static-index.d.ts +0 -0
  235. /package/dist/{target → service}/sse-parser.d.ts +0 -0
  236. /package/dist/{target → service}/sse-parser.js +0 -0
@@ -1,57 +1,26 @@
1
- import type { ActionDefinition, ActionRef, ExecutionEvent, ExecutionResult, JsonValue, Logger, ProcessAPI, ProgressReporter, RunRecord, RunStatus } from "@actiondock/sdk";
1
+ import type { ActionDefinition, ActionRef, ExecutionEvent, ExecutionResult, JsonValue, Logger, ProcessAPI, RunRecord, RunStatus } from "@actiondock/sdk";
2
2
  import type { ProjectConfig } from "../project/types.js";
3
- import type { ActionRunner, ExecutionHandle } from "../runtime/runner.js";
3
+ import type { ExecutionHandle } from "../runtime/runner.js";
4
4
  import type { Clock } from "../runtime/clock.js";
5
5
  import type { EventSink } from "../runtime/events.js";
6
6
  import type { RuntimeStorage } from "../storage/types.js";
7
- import type { RuntimePlatform } from "../platform/types.js";
8
- import type { ProcessOwner } from "../process/process-manager.js";
7
+ import type { ModuleLoader } from "../runtime/module-loader.js";
8
+ import { type PackageIdentity, type RunOptions, type InvocationContext, createInvocationContext, createRootInvocationContext } from "../invocation/types.js";
9
+ import type { LocalActionResolver } from "../runtime/runner.js";
10
+ export { createInvocationContext, createRootInvocationContext };
11
+ export type { PackageIdentity, RunOptions, InvocationContext, LocalActionResolver };
9
12
  /**
10
- * 执行参数选项。
13
+ * 跨包动作调用委托函数。
11
14
  */
12
- export interface ExecuteOptions {
13
- /** 外部取消信号 */
14
- signal?: AbortSignal;
15
- /** 超时时间(毫秒) */
16
- timeoutMs?: number;
17
- /** 配置临时覆盖字典 */
18
- config?: Record<string, JsonValue>;
19
- /** 幂等请求去重标识 */
20
- requestId?: string;
21
- /** 父运行 ID */
22
- parentRunId?: string;
23
- /** 根运行 ID */
24
- rootRunId?: string;
25
- /** 最大调用嵌套深度限制 */
26
- maxCallDepth?: number;
27
- /** 外部日志注入 */
28
- logger?: Logger;
29
- /** 外部进度报告器注入 */
30
- progress?: ProgressReporter;
31
- /** 外部进程执行器注入 */
32
- process?: ProcessAPI;
33
- /** 可选的底层运行平台契约 */
34
- platform?: RuntimePlatform;
35
- /** 执行宿主会话标识 */
36
- hostSessionId?: string;
37
- /** 包物理实例标识 */
38
- packageInstanceId?: string;
39
- /** 快照代次标识 */
40
- generationId?: string;
41
- /** 租户标识 */
42
- tenantId?: string;
43
- /** 主体标识 */
44
- principalId?: string;
45
- /** 执行归属所有者契约 */
46
- owner?: ProcessOwner;
47
- }
15
+ export type ActionInvoker = (childAction: ActionRef | string, childInput: unknown, context: InvocationContext) => Promise<unknown>;
48
16
  /**
49
17
  * 统一执行协调服务配置选项。
50
18
  */
51
19
  export interface ExecutionServiceOptions {
52
- packageId: string;
20
+ /** 包物理与快照身份标识值对象(必填单一事实源) */
21
+ identity: PackageIdentity;
53
22
  hostSessionId?: string;
54
- storage?: RuntimeStorage;
23
+ storage: RuntimeStorage;
55
24
  globalStorage?: RuntimeStorage;
56
25
  projectRoot?: string;
57
26
  projectConfig?: ProjectConfig;
@@ -62,30 +31,11 @@ export interface ExecutionServiceOptions {
62
31
  logger?: Logger;
63
32
  eventSink?: EventSink;
64
33
  maxActiveRuns?: number;
65
- maxCallDepth?: number;
66
- maxSubRuns?: number;
67
34
  ownerId?: string;
68
- actionResolver?: (ref: ActionRef | string) => ActionDefinition | undefined | Promise<ActionDefinition | undefined>;
69
- packageInstanceId?: string;
70
- generationId?: string;
71
- getStorageForPackage?: (packageId: string, projectRoot?: string) => RuntimeStorage;
72
- packageContextResolver?: (packageId: string) => Promise<{
73
- projectRoot?: string;
74
- projectConfig?: ProjectConfig;
75
- storage: RuntimeStorage;
76
- actions?: Map<string, ActionDefinition>;
77
- packageInstanceId?: string;
78
- generationId?: string;
79
- } | undefined> | {
80
- projectRoot?: string;
81
- projectConfig?: ProjectConfig;
82
- storage: RuntimeStorage;
83
- actions?: Map<string, ActionDefinition>;
84
- packageInstanceId?: string;
85
- generationId?: string;
86
- } | undefined;
35
+ actionResolver?: LocalActionResolver;
87
36
  customHome?: string;
88
- platform?: RuntimePlatform;
37
+ moduleLoader?: ModuleLoader;
38
+ actionInvoker?: ActionInvoker;
89
39
  }
90
40
  /**
91
41
  * 异步任务执行票据。
@@ -119,12 +69,16 @@ export type CancelResult = {
119
69
  * 统一执行协调服务接口。
120
70
  */
121
71
  export interface ExecutionService {
122
- /** 底层 Action 执行引擎(用于跨包上下文注入与动态解析委托) */
123
- readonly runner: ActionRunner;
72
+ /** 包物理与快照身份标识值对象 */
73
+ readonly identity: PackageIdentity;
74
+ /** 解析指定 Action 定义(支持本地注册、局部解析器及工程目录扫描) */
75
+ resolveAction?(ref: ActionRef | string): Promise<ActionDefinition | undefined>;
124
76
  /** 同步执行 Action 并等待终态结果 */
125
- execute(ref: ActionRef | string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionResult>;
77
+ execute(ref: ActionRef | string, input: JsonValue, context: InvocationContext): Promise<ExecutionResult>;
78
+ /** 同步执行 Action 并等待终态结果(execute 统一别名) */
79
+ run(ref: ActionRef | string, input: JsonValue, context: InvocationContext): Promise<ExecutionResult>;
126
80
  /** 异步启动 Action 并立即返回任务票据 */
127
- start(ref: ActionRef | string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionTicket>;
81
+ start(ref: ActionRef | string, input: JsonValue, context: InvocationContext): Promise<ExecutionTicket>;
128
82
  /** 根据 ID 获取运行记录 */
129
83
  get(runId: string): Promise<RunRecord | undefined>;
130
84
  /** 取消指定的在运行任务 */
@@ -141,6 +95,8 @@ export interface ExecutionService {
141
95
  registerAction(id: string, action: ActionDefinition): void;
142
96
  /** 按 ID 检索已注册的 Action 定义 */
143
97
  getAction(id: string): ActionDefinition | undefined;
98
+ /** 设置子任务动作调用委托器 */
99
+ setActionInvoker?(invoker?: ActionInvoker): void;
144
100
  /** 优雅关闭服务并等待活跃任务收尾 */
145
101
  close(options?: {
146
102
  graceMs?: number;
@@ -1 +1,2 @@
1
- export {};
1
+ import { createInvocationContext, createRootInvocationContext, } from "../invocation/types.js";
2
+ export { createInvocationContext, createRootInvocationContext };
@@ -3,18 +3,17 @@
3
3
  */
4
4
  export type Extractor<T> = (item: T) => unknown;
5
5
  /**
6
- * 安全地将模式字符串、数组或现有正则编译为不区分大小写的 RegExp 正则表达式。
7
- * 若正则语法不合法,自动对特殊字符进行转义并降级为字面量匹配正则,保证零 Crash。
6
+ * 安全地将模式字符串、数组或现有正则编译为不区分大小写的匹配正则。
8
7
  *
9
- * @param intent 意图关键词、正则或数组
10
- */
11
- export declare function compileIntentRegex(intent?: string | string[] | RegExp | null): RegExp | null;
12
- /**
13
- * 递归检查某个值(包括嵌套的数组或对象结构)是否匹配给定的正则表达式。
8
+ * 编译策略:
9
+ * - 显式传入 RegExp 实例:原样使用(调用方自担回溯风险)
10
+ * - 字符串以 re: 前缀声明:按正则编译,语法非法时转义降级为字面量
11
+ * - 其余字符串与数组:一律转义为字面量子串匹配(多关键词以 | 分隔时保留 OR 语义),
12
+ * 消除用户可控输入的重灾回溯面
14
13
  *
15
- * @param value 待检测的任意数据类型
16
- * @param regex 正则表达式
14
+ * @param intent 意图关键词、显式正则(re: 前缀)或数组
17
15
  */
16
+ export declare function compileIntentRegex(intent?: string | string[] | RegExp | null): RegExp | null;
18
17
  export declare function matchIntent(value: unknown, regex: RegExp): boolean;
19
18
  export interface FilterResult<T> {
20
19
  items: T[];
@@ -1,8 +1,29 @@
1
1
  /**
2
- * 安全地将模式字符串、数组或现有正则编译为不区分大小写的 RegExp 正则表达式。
3
- * 若正则语法不合法,自动对特殊字符进行转义并降级为字面量匹配正则,保证零 Crash。
2
+ * 显式开启正则模式的意图前缀:以此前缀声明的意图才按正则编译,其余一律按字面子串匹配。
3
+ * 目的:意图参数来自用户输入(CLI 与 HTTP 查询参数),直接编译正则存在灾难性回溯(ReDoS)风险。
4
+ */
5
+ const REGEX_MODE_PREFIX = "re:";
6
+ /**
7
+ * 将任意字符串转义为字面量匹配正则(保留 | 分隔的多关键词 OR 语义)。
8
+ */
9
+ function escapeAsLiteralPattern(patternStr) {
10
+ return patternStr
11
+ .split("|")
12
+ .map((part) => part.trim())
13
+ .filter(Boolean)
14
+ .map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
15
+ .join("|");
16
+ }
17
+ /**
18
+ * 安全地将模式字符串、数组或现有正则编译为不区分大小写的匹配正则。
19
+ *
20
+ * 编译策略:
21
+ * - 显式传入 RegExp 实例:原样使用(调用方自担回溯风险)
22
+ * - 字符串以 re: 前缀声明:按正则编译,语法非法时转义降级为字面量
23
+ * - 其余字符串与数组:一律转义为字面量子串匹配(多关键词以 | 分隔时保留 OR 语义),
24
+ * 消除用户可控输入的重灾回溯面
4
25
  *
5
- * @param intent 意图关键词、正则或数组
26
+ * @param intent 意图关键词、显式正则(re: 前缀)或数组
6
27
  */
7
28
  export function compileIntentRegex(intent) {
8
29
  if (!intent)
@@ -10,6 +31,7 @@ export function compileIntentRegex(intent) {
10
31
  if (intent instanceof RegExp)
11
32
  return intent;
12
33
  let patternStr;
34
+ let regexMode = false;
13
35
  if (Array.isArray(intent)) {
14
36
  const valid = intent.map((s) => s.trim()).filter(Boolean);
15
37
  if (valid.length === 0)
@@ -20,25 +42,39 @@ export function compileIntentRegex(intent) {
20
42
  patternStr = intent.trim();
21
43
  if (!patternStr)
22
44
  return null;
45
+ if (patternStr.startsWith(REGEX_MODE_PREFIX)) {
46
+ const rest = patternStr.slice(REGEX_MODE_PREFIX.length).trim();
47
+ if (!rest)
48
+ return null;
49
+ patternStr = rest;
50
+ regexMode = true;
51
+ }
23
52
  }
24
- try {
25
- return new RegExp(patternStr, "i");
26
- }
27
- catch {
28
- const escaped = patternStr.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
29
- return new RegExp(escaped, "i");
53
+ if (regexMode) {
54
+ try {
55
+ return new RegExp(patternStr, "i");
56
+ }
57
+ catch {
58
+ // 正则语法非法时降级为字面量匹配,保证零 Crash
59
+ }
30
60
  }
61
+ return new RegExp(escapeAsLiteralPattern(patternStr), "i");
31
62
  }
32
63
  /**
33
64
  * 递归检查某个值(包括嵌套的数组或对象结构)是否匹配给定的正则表达式。
34
65
  *
66
+ * 防护:对象序列化长度超过 MATCH_TEXT_LIMIT 时拒绝全文匹配,避免对超大对象执行回溯敏感的正则扫描。
67
+ *
35
68
  * @param value 待检测的任意数据类型
36
69
  * @param regex 正则表达式
37
70
  */
71
+ const MATCH_TEXT_LIMIT = 64 * 1024;
38
72
  export function matchIntent(value, regex) {
39
73
  if (value === undefined || value === null)
40
74
  return false;
41
75
  if (typeof value === "string") {
76
+ if (value.length > MATCH_TEXT_LIMIT)
77
+ return false;
42
78
  return regex.test(value);
43
79
  }
44
80
  if (typeof value === "number" || typeof value === "boolean") {
@@ -53,7 +89,10 @@ export function matchIntent(value, regex) {
53
89
  }
54
90
  if (typeof value === "object") {
55
91
  try {
56
- return regex.test(JSON.stringify(value));
92
+ const text = JSON.stringify(value);
93
+ if (text === undefined || text.length > MATCH_TEXT_LIMIT)
94
+ return false;
95
+ return regex.test(text);
57
96
  }
58
97
  catch {
59
98
  return false;
@@ -0,0 +1,4 @@
1
+ export * from "../catalog/graph.js";
2
+ export { parseActionRef, resolveAction } from "../catalog/resolve-action.js";
3
+ export { resolvePlaybook } from "../catalog/resolve-playbook.js";
4
+ export { DefaultActionCatalog, type ActionCatalog } from "../catalog/action-catalog.js";
@@ -0,0 +1,4 @@
1
+ export * from "../catalog/graph.js";
2
+ export { parseActionRef, resolveAction } from "../catalog/resolve-action.js";
3
+ export { resolvePlaybook } from "../catalog/resolve-playbook.js";
4
+ export { DefaultActionCatalog } from "../catalog/action-catalog.js";
@@ -1,19 +1,17 @@
1
1
  import type { ActionRef, ExecutionEvent, ExecutionResult, JsonValue, RunRecord } from "@actiondock/sdk";
2
- import type { ActionDockApp, ActionSpec, ActionSummary, ListActionsOptions, PackageInfo, PlaybookSpec, PlaybookSummary } from "../app/types.js";
3
- import type { CancelResult, ExecuteOptions, ExecutionTicket } from "../execution/types.js";
2
+ import type { PackageInfo, PackageRuntime, ActionSpec, ActionSummary, ListActionsOptions, PlaybookSpec, PlaybookSummary } from "../package/types.js";
3
+ import type { CancelResult, ExecutionTicket } from "../execution/types.js";
4
+ import { type RunOptions } from "../invocation/types.js";
5
+ import { InvocationPolicy } from "../invocation/policy.js";
4
6
  import type { ActionDockHost, ActionDockHostOptions } from "./types.js";
5
- /**
6
- * ActionDock 统一多包宿主容器默认实现。
7
- * 负责聚合与调度多个 ActionDockApp 实例,提供跨包引用路由、依赖声明校验与资源配额控制。
8
- */
7
+ import type { ConfigValueView, ListRunsOptions, StateScopeOptions } from "../service/types.js";
8
+ import type { StateEntry } from "../storage/types.js";
9
9
  export declare class DefaultActionDockHost implements ActionDockHost {
10
10
  readonly hostSessionId: string;
11
11
  readonly options: ActionDockHostOptions;
12
- private apps;
13
- private readonly internallyCreatedApps;
14
- private activeSubRunsPerRoot;
12
+ private runtimes;
13
+ readonly policy: InvocationPolicy;
15
14
  private hostPublicPackageIds;
16
- private resolver?;
17
15
  private maxCallDepth;
18
16
  private maxSubRuns;
19
17
  private eventSink;
@@ -21,11 +19,31 @@ export declare class DefaultActionDockHost implements ActionDockHost {
21
19
  private dataDirLock?;
22
20
  private failedLinkedPackages;
23
21
  private failedAutoLoad?;
24
- /** 透传给内部创建 App 的存储收割开关(Host 默认持有者身份,显式可关) */
22
+ /** 透传给内部创建 Runtime 的存储收割开关(Host 默认持有者身份,显式可关) */
25
23
  private recoverOrphans;
26
- constructor(options?: ActionDockHostOptions);
24
+ private graph;
25
+ private catalog;
26
+ private globalStorage?;
27
+ constructor(options?: ActionDockHostOptions, internalOptions?: {
28
+ deferInit?: boolean;
29
+ });
30
+ private initializeSync;
31
+ initializeAsync(): Promise<void>;
32
+ /**
33
+ * 安全回滚初始化失败时所占用的资源。
34
+ *
35
+ * 同步语境(构造函数路径)下对 runtime.close() 采用 fire-and-forget:
36
+ * 仅附加吞没异常的 catch 处理器,不 await,避免构造链路引入异步;
37
+ * 异步语境下逐个 await 全部 runtime.close() 后再依次释放全局存储与目录锁。
38
+ */
39
+ private rollbackResources;
27
40
  /**
28
- * 阶段函数:注册显式传入的 packages 列表(现成 App 实例或 AppOptions 配置)。
41
+ * 异步安全回滚初始化失败时所占用的资源。
42
+ */
43
+ rollbackInitialization(): Promise<void>;
44
+ private rollbackSync;
45
+ /**
46
+ * 阶段函数:注册显式传入的 packages 列表(PackageRuntimeOptions 配置或包目录物理路径)。
29
47
  */
30
48
  private registerExplicitPackages;
31
49
  /**
@@ -43,40 +61,64 @@ export declare class DefaultActionDockHost implements ActionDockHost {
43
61
  * 加载失败的链接包记录至 failedLinkedPackages 诊断并在调阅时透传精准失败原因。
44
62
  */
45
63
  private registerLinkedPackages;
46
- private resolvePackageContext;
47
- private bindApp;
48
- /** 路由可见性上下文(公开包集合与依赖解析器) */
49
- private visibility;
50
- getApp(packageId: string): ActionDockApp | undefined;
51
- listApps(): ActionDockApp[];
64
+ private bindRuntime;
52
65
  /**
53
- * 获取自动加载工程的失败诊断信息。
54
- * 仅自动探测场景会记录此诊断;显式传入 projectRoot 的加载失败会直接抛出,不产生此诊断。
66
+ * 构造应用专属动作调用委托器。
67
+ * 铁律 2:跨包调用改走 ActionInvoker 回到 Host 执行主链,经由唯一的 InvocationPolicy 授权后调用目标 Package 的 ExecutionService。
55
68
  */
56
- getAutoLoadFailure(): {
57
- projectRoot: string;
58
- error: string;
59
- } | undefined;
60
- private registerAppInternal;
61
- registerApp(app: ActionDockApp): void;
69
+ private createActionInvoker;
70
+ /** 路由可见性上下文(公开包集合与包依赖图) */
71
+ private visibility;
72
+ private rebuildGraphAndCatalog;
73
+ getRuntime(packageId: string): PackageRuntime | undefined;
74
+ listRuntimes(): PackageRuntime[];
75
+ private registerRuntimeInternal;
76
+ registerRuntime(runtime: PackageRuntime): void;
62
77
  info(): Promise<PackageInfo[]>;
63
78
  listActions(options?: ListActionsOptions): Promise<ActionSummary[]>;
64
79
  describeAction(ref: ActionRef | string): Promise<ActionSpec>;
65
- listPlaybooks(): Promise<PlaybookSummary[]>;
80
+ listPlaybooks(options?: {
81
+ intent?: string;
82
+ package?: string;
83
+ }): Promise<PlaybookSummary[]>;
66
84
  describePlaybook(id: string): Promise<PlaybookSpec>;
67
- runAction(ref: ActionRef | string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionResult>;
68
- startAction(ref: ActionRef | string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionTicket>;
85
+ runAction(ref: ActionRef | string, input: JsonValue, options?: RunOptions): Promise<ExecutionResult>;
86
+ startAction(ref: ActionRef | string, input: JsonValue, options?: RunOptions): Promise<ExecutionTicket>;
69
87
  getRun(runId: string): Promise<RunRecord | undefined>;
88
+ listRuns(query?: ListRunsOptions): Promise<RunRecord[]>;
89
+ clearRuns(options?: {
90
+ packageId?: string;
91
+ actionId?: string;
92
+ status?: string;
93
+ olderThanMs?: number;
94
+ }): Promise<number>;
70
95
  cancelRun(runId: string, reason?: string): Promise<CancelResult>;
71
96
  events(runId: string, options?: {
72
97
  after?: number | string;
73
98
  signal?: AbortSignal;
74
99
  maxQueueSize?: number;
75
100
  }): AsyncIterable<ExecutionEvent>;
101
+ private getGlobalStorage;
102
+ private findDeclaredConfigItem;
103
+ private resolveRuntime;
104
+ /**
105
+ * 解析目标包运行时:未命中时抛出统一的包未找到错误。
106
+ */
107
+ private requireRuntime;
108
+ getConfig(packageId: string, key: string): Promise<ConfigValueView>;
109
+ setConfig(packageId: string, key: string, value: JsonValue): Promise<void>;
110
+ deleteConfig(packageId: string, key: string): Promise<boolean>;
111
+ listConfig(packageId: string): Promise<ConfigValueView[]>;
112
+ getState<T extends JsonValue = JsonValue>(packageId: string, actionId: string, key: string, options?: StateScopeOptions): Promise<T | undefined>;
113
+ setState<T extends JsonValue = JsonValue>(packageId: string, actionId: string, key: string, value: T, options?: StateScopeOptions): Promise<void>;
114
+ deleteState(packageId: string, actionId: string, key: string, options?: StateScopeOptions): Promise<boolean>;
115
+ listStateKeys(packageId: string, actionId: string, options?: StateScopeOptions): Promise<string[]>;
116
+ clearState(packageId: string, actionId: string, options?: StateScopeOptions): Promise<number>;
117
+ listStateEntries(packageId: string, options?: any): Promise<StateEntry[]>;
76
118
  /**
77
119
  * 优雅关闭宿主容器。
78
- * 仅对内部创建的 App 实例执行 close 并安全释放底层资源;
79
- * 外部传入借用的 App 实例生命周期完全由调用方负责管理,Host 关闭时仅解绑引用并清理自身内部实例。
120
+ * 仅对内部创建的 Runtime 实例执行 close 并安全释放底层资源;
121
+ * 外部传入借用的 Runtime 实例生命周期完全由调用方负责管理,Host 关闭时仅解绑引用并清理自身内部实例。
80
122
  */
81
123
  close(options?: {
82
124
  graceMs?: number;