@actiondock/core 2.6.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 (268) 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 +122 -10
  18. package/dist/errors.js +123 -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 -22
  33. package/dist/index.js +19 -21
  34. package/dist/input/advice.d.ts +104 -0
  35. package/dist/input/advice.js +716 -0
  36. package/dist/input/describe.d.ts +106 -0
  37. package/dist/input/describe.js +176 -0
  38. package/dist/input/file-input.d.ts +54 -0
  39. package/dist/input/file-input.js +124 -0
  40. package/dist/input/flat-decode.d.ts +11 -0
  41. package/dist/input/flat-decode.js +13 -0
  42. package/dist/input/flat-errors.d.ts +71 -0
  43. package/dist/input/flat-errors.js +87 -0
  44. package/dist/input/flat-materializer.d.ts +29 -0
  45. package/dist/input/flat-materializer.js +177 -0
  46. package/dist/input/flat-parser.d.ts +50 -0
  47. package/dist/input/flat-parser.js +169 -0
  48. package/dist/input/flat-predicates.d.ts +34 -0
  49. package/dist/input/flat-predicates.js +50 -0
  50. package/dist/input/index.d.ts +14 -0
  51. package/dist/input/index.js +14 -0
  52. package/dist/input/input-resolver.d.ts +63 -0
  53. package/dist/input/input-resolver.js +254 -0
  54. package/dist/input/json-depth-scanner.d.ts +17 -0
  55. package/dist/input/json-depth-scanner.js +49 -0
  56. package/dist/input/metadata.d.ts +99 -0
  57. package/dist/input/metadata.js +99 -0
  58. package/dist/input/stdin-input.d.ts +26 -0
  59. package/dist/input/stdin-input.js +125 -0
  60. package/dist/input/utf8.d.ts +19 -0
  61. package/dist/input/utf8.js +36 -0
  62. package/dist/input/validation-mapper.d.ts +27 -0
  63. package/dist/input/validation-mapper.js +144 -0
  64. package/dist/invocation/index.d.ts +2 -0
  65. package/dist/invocation/index.js +2 -0
  66. package/dist/invocation/policy.d.ts +157 -0
  67. package/dist/invocation/policy.js +231 -0
  68. package/dist/invocation/types.d.ts +172 -0
  69. package/dist/invocation/types.js +97 -0
  70. package/dist/ipc/diagnostic.d.ts +0 -12
  71. package/dist/ipc/diagnostic.js +0 -21
  72. package/dist/ipc/host.d.ts +4 -4
  73. package/dist/ipc/host.js +44 -47
  74. package/dist/ipc/index.d.ts +1 -1
  75. package/dist/ipc/index.js +1 -1
  76. package/dist/ipc/service.d.ts +40 -0
  77. package/dist/ipc/service.js +349 -0
  78. package/dist/ipc/types.d.ts +21 -15
  79. package/dist/json/index.d.ts +1 -0
  80. package/dist/json/index.js +1 -0
  81. package/dist/json/value-validator.d.ts +88 -0
  82. package/dist/json/value-validator.js +330 -0
  83. package/dist/node/index.d.ts +1 -0
  84. package/dist/node/index.js +1 -0
  85. package/dist/node/module-loader.d.ts +63 -0
  86. package/dist/node/module-loader.js +112 -0
  87. package/dist/package/index.d.ts +23 -0
  88. package/dist/package/index.js +18 -0
  89. package/dist/{app/app.d.ts → package/runtime.d.ts} +41 -20
  90. package/dist/{app/app.js → package/runtime.js} +140 -95
  91. package/dist/{app → package}/static-index.js +58 -41
  92. package/dist/package/storage-view.d.ts +13 -0
  93. package/dist/package/storage-view.js +22 -0
  94. package/dist/{app → package}/types.d.ts +76 -57
  95. package/dist/package/types.js +22 -0
  96. package/dist/platform/index.d.ts +1 -1
  97. package/dist/platform/index.js +1 -1
  98. package/dist/platform/node.d.ts +48 -0
  99. package/dist/platform/node.js +96 -0
  100. package/dist/platform/types.d.ts +0 -9
  101. package/dist/process/control-arbiter.d.ts +2 -1
  102. package/dist/process/control-arbiter.js +1 -2
  103. package/dist/process/driver.d.ts +9 -8
  104. package/dist/process/driver.js +11 -22
  105. package/dist/process/index.d.ts +2 -0
  106. package/dist/process/index.js +2 -0
  107. package/dist/process/managed-record.d.ts +2 -2
  108. package/dist/process/process-driver.d.ts +109 -0
  109. package/dist/process/process-driver.js +650 -0
  110. package/dist/process/process-executor.d.ts +47 -0
  111. package/dist/process/process-executor.js +296 -0
  112. package/dist/process/process-manager.js +48 -26
  113. package/dist/process/run-executor.js +12 -12
  114. package/dist/profile/client-actions.js +2 -2
  115. package/dist/profile/client-health.js +3 -2
  116. package/dist/profile/client-query.js +5 -6
  117. package/dist/profile/client-transport.d.ts +19 -17
  118. package/dist/profile/client-transport.js +48 -80
  119. package/dist/profile/client.d.ts +2 -2
  120. package/dist/profile/client.js +1 -1
  121. package/dist/profile/index.d.ts +1 -0
  122. package/dist/profile/index.js +1 -0
  123. package/dist/profile/manager.d.ts +5 -0
  124. package/dist/profile/manager.js +41 -6
  125. package/dist/project/closure.js +2 -2
  126. package/dist/project/index.d.ts +8 -1
  127. package/dist/project/index.js +10 -1
  128. package/dist/project/init.js +2 -2
  129. package/dist/project/loader.d.ts +1 -1
  130. package/dist/project/loader.js +26 -29
  131. package/dist/project/transactions.js +5 -10
  132. package/dist/registry/index.d.ts +3 -1
  133. package/dist/registry/index.js +2 -1
  134. package/dist/registry/lock.d.ts +28 -7
  135. package/dist/registry/lock.js +136 -16
  136. package/dist/registry/registry.d.ts +1 -5
  137. package/dist/registry/registry.js +1 -53
  138. package/dist/registry/scan.d.ts +0 -15
  139. package/dist/registry/scan.js +0 -59
  140. package/dist/registry/store.d.ts +42 -0
  141. package/dist/registry/store.js +43 -0
  142. package/dist/registry/types.d.ts +0 -24
  143. package/dist/runtime/action-collection.d.ts +1 -1
  144. package/dist/runtime/action-registry.d.ts +0 -4
  145. package/dist/runtime/action-registry.js +0 -7
  146. package/dist/runtime/context.js +5 -11
  147. package/dist/runtime/events.js +3 -6
  148. package/dist/runtime/identity.d.ts +22 -0
  149. package/dist/runtime/identity.js +10 -0
  150. package/dist/runtime/index.d.ts +1 -2
  151. package/dist/runtime/index.js +1 -2
  152. package/dist/runtime/module-loader.d.ts +2 -34
  153. package/dist/runtime/module-loader.js +1 -16
  154. package/dist/runtime/process.d.ts +6 -24
  155. package/dist/runtime/process.js +1 -118
  156. package/dist/runtime/run-persistence.js +2 -5
  157. package/dist/runtime/runner.d.ts +33 -103
  158. package/dist/runtime/runner.js +142 -404
  159. package/dist/runtime/standalone.d.ts +37 -9
  160. package/dist/runtime/standalone.js +195 -136
  161. package/dist/schema/index.d.ts +1 -0
  162. package/dist/schema/index.js +1 -0
  163. package/dist/schema/validator.d.ts +10 -0
  164. package/dist/schema/validator.js +48 -54
  165. package/dist/server/body.d.ts +16 -8
  166. package/dist/server/body.js +33 -16
  167. package/dist/server/dispatcher.d.ts +6 -10
  168. package/dist/server/dispatcher.js +24 -32
  169. package/dist/server/http-server.d.ts +87 -0
  170. package/dist/server/http-server.js +304 -0
  171. package/dist/server/index.d.ts +11 -0
  172. package/dist/server/index.js +10 -0
  173. package/dist/server/mcp-endpoint.d.ts +61 -0
  174. package/dist/server/mcp-endpoint.js +118 -0
  175. package/dist/server/routes/actions.js +34 -28
  176. package/dist/server/routes/common.d.ts +10 -14
  177. package/dist/server/routes/common.js +32 -56
  178. package/dist/server/routes/config.js +54 -64
  179. package/dist/server/routes/doctor.d.ts +1 -1
  180. package/dist/server/routes/doctor.js +10 -18
  181. package/dist/server/routes/health.d.ts +1 -1
  182. package/dist/server/routes/health.js +2 -3
  183. package/dist/server/routes/info.d.ts +2 -2
  184. package/dist/server/routes/info.js +12 -13
  185. package/dist/server/routes/playbooks.js +16 -29
  186. package/dist/server/routes/runs.js +95 -117
  187. package/dist/server/routes/state.js +63 -62
  188. package/dist/server/server.d.ts +2 -2
  189. package/dist/server/server.js +43 -227
  190. package/dist/server/types.d.ts +8 -19
  191. package/dist/service/factory.d.ts +12 -0
  192. package/dist/service/factory.js +85 -0
  193. package/dist/{target → service}/index.d.ts +1 -1
  194. package/dist/{target → service}/index.js +1 -1
  195. package/dist/service/local.d.ts +27 -0
  196. package/dist/service/local.js +138 -0
  197. package/dist/{target → service}/remote-errors.d.ts +3 -6
  198. package/dist/service/remote-errors.js +38 -0
  199. package/dist/{target → service}/remote-polling.d.ts +2 -2
  200. package/dist/{target → service}/remote-polling.js +8 -8
  201. package/dist/service/remote.d.ts +34 -0
  202. package/dist/service/remote.js +634 -0
  203. package/dist/service/sse-stream.d.ts +24 -0
  204. package/dist/service/sse-stream.js +139 -0
  205. package/dist/service/types.d.ts +272 -0
  206. package/dist/service/types.js +32 -0
  207. package/dist/storage/data-dir-lock.js +10 -5
  208. package/dist/storage/driver.d.ts +2 -1
  209. package/dist/storage/driver.js +3 -52
  210. package/dist/storage/index.d.ts +1 -0
  211. package/dist/storage/index.js +1 -0
  212. package/dist/storage/lock-core.d.ts +2 -6
  213. package/dist/storage/lock-core.js +4 -17
  214. package/dist/storage/params.d.ts +2 -8
  215. package/dist/storage/params.js +2 -8
  216. package/dist/storage/sqlite-driver.d.ts +40 -0
  217. package/dist/storage/sqlite-driver.js +116 -0
  218. package/dist/storage/sqlite.js +21 -6
  219. package/dist/storage/types.d.ts +4 -4
  220. package/dist/storage/types.js +2 -2
  221. package/dist/utils/index.d.ts +53 -0
  222. package/dist/utils/index.js +99 -4
  223. package/dist/utils/process.d.ts +10 -0
  224. package/dist/utils/process.js +21 -0
  225. package/dist/version.d.ts +1 -1
  226. package/dist/version.js +1 -1
  227. package/package.json +41 -3
  228. package/dist/app/index.d.ts +0 -2
  229. package/dist/app/index.js +0 -2
  230. package/dist/app/types.js +0 -1
  231. package/dist/catalog/action-index.d.ts +0 -9
  232. package/dist/catalog/action-index.js +0 -95
  233. package/dist/catalog/action-resolver.d.ts +0 -20
  234. package/dist/catalog/action-resolver.js +0 -95
  235. package/dist/catalog/location-registry.d.ts +0 -15
  236. package/dist/catalog/location-registry.js +0 -138
  237. package/dist/catalog/package-catalog.d.ts +0 -7
  238. package/dist/catalog/package-catalog.js +0 -77
  239. package/dist/catalog/types.d.ts +0 -68
  240. package/dist/catalog/types.js +0 -1
  241. package/dist/export/index.d.ts +0 -1
  242. package/dist/export/index.js +0 -1
  243. package/dist/export/templates.d.ts +0 -71
  244. package/dist/export/templates.js +0 -623
  245. package/dist/ipc/target.d.ts +0 -74
  246. package/dist/ipc/target.js +0 -365
  247. package/dist/platform/default.d.ts +0 -38
  248. package/dist/platform/default.js +0 -78
  249. package/dist/project/resolver.d.ts +0 -116
  250. package/dist/project/resolver.js +0 -376
  251. package/dist/registry/resolve.d.ts +0 -62
  252. package/dist/registry/resolve.js +0 -195
  253. package/dist/runtime/execution-manager.d.ts +0 -48
  254. package/dist/runtime/execution-manager.js +0 -66
  255. package/dist/runtime/package-runner-factory.d.ts +0 -82
  256. package/dist/runtime/package-runner-factory.js +0 -186
  257. package/dist/target/local.d.ts +0 -53
  258. package/dist/target/local.js +0 -349
  259. package/dist/target/remote-errors.js +0 -51
  260. package/dist/target/remote.d.ts +0 -86
  261. package/dist/target/remote.js +0 -818
  262. package/dist/target/target.d.ts +0 -6
  263. package/dist/target/target.js +0 -37
  264. package/dist/target/types.d.ts +0 -261
  265. package/dist/target/types.js +0 -35
  266. /package/dist/{app → package}/static-index.d.ts +0 -0
  267. /package/dist/{target → service}/sse-parser.d.ts +0 -0
  268. /package/dist/{target → service}/sse-parser.js +0 -0
@@ -1,12 +1,14 @@
1
- import type { ActionDefinition, ActionRef, ExecutionEvent, ExecutionResult, JsonValue, Logger, ProcessAPI, RunRecord } from "@actiondock/sdk";
2
- import type { CancelResult, ExecuteOptions, ExecutionService, ExecutionTicket } from "../execution/types.js";
1
+ import type { ActionDefinition, ExecutionEvent, ExecutionResult, JsonValue, Logger, ProcessAPI, RunRecord } from "@actiondock/sdk";
2
+ import type { ActionInvoker, CancelResult, ExecutionTicket, LocalActionResolver } from "../execution/types.js";
3
+ import type { InvocationContext, RunOptions } from "../invocation/types.js";
3
4
  import type { ConfigItemDefinition, ProjectConfig } from "../project/types.js";
4
- import type { Clock } from "../runtime/clock.js";
5
5
  import type { EventSink } from "../runtime/events.js";
6
6
  import type { RuntimePlatform, StorageFactory, StorageFactoryOptions } from "../platform/types.js";
7
- import type { RuntimeStorage } from "../storage/types.js";
8
- import type { ConfigValueView, StateScopeOptions } from "../target/types.js";
9
- export type { ConfigValueView, RuntimePlatform, StateScopeOptions, StorageFactory, StorageFactoryOptions };
7
+ import type { RuntimeStorage, StateEntry } from "../storage/types.js";
8
+ import type { Clock } from "../storage/clock.js";
9
+ import type { ConfigValueView, ListRunsOptions, StateScopeOptions } from "../service/types.js";
10
+ import type { PackageIdentity } from "../runtime/identity.js";
11
+ export type { ConfigValueView, ListRunsOptions, PackageIdentity, RuntimePlatform, StateScopeOptions, StorageFactory, StorageFactoryOptions };
10
12
  /**
11
13
  * 宏包信息契约。
12
14
  */
@@ -95,6 +97,18 @@ export interface ListActionsOptions {
95
97
  /** 标识前缀过滤 */
96
98
  prefix?: string;
97
99
  }
100
+ /**
101
+ * 对 Action 摘要列表应用统一的检索过滤(标签、模糊关键词与标识前缀)。
102
+ *
103
+ * PackageRuntime 与 Host 两级列表查询的单一事实源:
104
+ * 两处过滤块逐字相同,收敛后调用方仅需在外层叠加各自的特有逻辑
105
+ * (Host 版在过滤前额外完成可见性筛选与跨包限定名改写)。
106
+ */
107
+ export declare function applyActionSummaryFilters<T extends {
108
+ id: string;
109
+ description?: string;
110
+ tags?: string[];
111
+ }>(summaries: readonly T[], options?: ListActionsOptions): T[];
98
112
  /**
99
113
  * Playbook 规程简要摘要条目。
100
114
  */
@@ -137,21 +151,13 @@ export interface StateOptions {
137
151
  ttl?: number;
138
152
  }
139
153
  /**
140
- * ActionDockApp 初始化配置选项。
154
+ * PackageRuntime 初始化公开配置选项(面向用户与外部配置)。
141
155
  */
142
- export interface ActionDockAppOptions {
156
+ export interface PackageRuntimeOptions {
143
157
  /** 项目根目录绝对物理路径 */
144
158
  packageRoot?: string;
145
159
  /** 项目配置文件 (actiondock.json) 对象 */
146
160
  projectConfig?: ProjectConfig;
147
- /** 显式注入的运行时平台适配 */
148
- platform?: RuntimePlatform;
149
- /** 显式注入的项目级运行时存储实例 */
150
- storage?: RuntimeStorage;
151
- /** 显式注入的全局运行时存储实例 */
152
- globalStorage?: RuntimeStorage;
153
- /** 显式注入的事件接收器 */
154
- eventSink?: EventSink;
155
161
  /** 数据持久化存储目录 */
156
162
  dataDir?: string;
157
163
  /** 自定义家目录绝对路径 */
@@ -165,31 +171,11 @@ export interface ActionDockAppOptions {
165
171
  } | (ActionDefinition & {
166
172
  id: string;
167
173
  })> | Record<string, ActionDefinition>;
168
- /** 跨包或动态 Action 解析器 */
169
- actionResolver?: (ref: ActionRef | string) => ActionDefinition | undefined | Promise<ActionDefinition | undefined>;
170
- /** 跨包运行上下文解析委托函数 */
171
- packageContextResolver?: (packageId: string) => Promise<{
172
- projectRoot?: string;
173
- projectConfig?: ProjectConfig;
174
- storage: RuntimeStorage;
175
- actions?: Map<string, ActionDefinition>;
176
- packageInstanceId?: string;
177
- generationId?: string;
178
- } | undefined> | {
179
- projectRoot?: string;
180
- projectConfig?: ProjectConfig;
181
- storage: RuntimeStorage;
182
- actions?: Map<string, ActionDefinition>;
183
- packageInstanceId?: string;
184
- generationId?: string;
185
- } | undefined;
186
- /** 包物理实例标识 */
187
- packageInstanceId?: string;
188
- /** 快照代次标识 */
189
- generationId?: string;
174
+ /** 仅支持当前包局部 Action 的动态解析委托函数 */
175
+ actionResolver?: LocalActionResolver;
190
176
  /**
191
177
  * 是否以数据目录持有者身份打开存储:true 时构造阶段收割遗留非终态运行记录。
192
- * 默认 true(App 主路径即持有者);外部工具创建旁观视图时置 false。
178
+ * 默认 true(PackageRuntime 主路径即持有者);外部工具创建旁观视图时置 false。
193
179
  */
194
180
  recoverOrphans?: boolean;
195
181
  /** 临时配置覆写字典 */
@@ -202,8 +188,8 @@ export interface ActionDockAppOptions {
202
188
  maxCallDepth?: number;
203
189
  /** 最大子任务数限制 */
204
190
  maxSubRuns?: number;
205
- /** 执行宿主会话标识 */
206
- hostSessionId?: string;
191
+ /** 显式注入的运行时平台适配 */
192
+ platform?: RuntimePlatform;
207
193
  /** 日志记录器 */
208
194
  logger?: Logger;
209
195
  /** 时钟源 */
@@ -214,11 +200,34 @@ export interface ActionDockAppOptions {
214
200
  exposeDebugInfo?: boolean;
215
201
  }
216
202
  /**
217
- * ActionDock 统一应用领域契约。
218
- * 作为单个 Action Package 的唯一运行单元与对外门面。
203
+ * PackageRuntime 内部装配选项(框架内部接线与依赖注入)。
204
+ *
205
+ * 普通公开 API 仅暴露 PackageRuntimeOptions,此选项仅在 Host 容器或核心测试装配时使用。
219
206
  */
220
- export interface ActionDockApp {
221
- /** 包唯一标识 */
207
+ export interface PackageRuntimeInternalOptions extends PackageRuntimeOptions {
208
+ /** 显式注入的包物理与快照身份标识值对象 */
209
+ identity?: PackageIdentity;
210
+ /** 显式注入的项目级运行时存储实例 */
211
+ storage?: RuntimeStorage;
212
+ /** 显式注入的全局运行时存储实例 */
213
+ globalStorage?: RuntimeStorage;
214
+ /** 显式注入的事件接收器 */
215
+ eventSink?: EventSink;
216
+ /** 子任务动作调用委托器 */
217
+ actionInvoker?: ActionInvoker;
218
+ /** 执行宿主会话标识 */
219
+ hostSessionId?: string;
220
+ }
221
+ /**
222
+ * 单个 Action Package 的运行时领域契约(PackageRuntime)。
223
+ *
224
+ * 铁律 1 执行主链核心节点:
225
+ * Host -> Resolution -> PackageRuntime -> ExecutionService -> ActionRunner -> Action
226
+ */
227
+ export interface PackageRuntime {
228
+ /** 包唯一物理与快照身份标识值对象(只在创建时生成一次) */
229
+ readonly identity: PackageIdentity;
230
+ /** 包唯一逻辑标识 */
222
231
  readonly packageId: string;
223
232
  /** 包物理实例标识 */
224
233
  readonly packageInstanceId?: string;
@@ -228,16 +237,11 @@ export interface ActionDockApp {
228
237
  readonly packageRoot?: string;
229
238
  /** 项目配置对象(actiondock.json 解析结果) */
230
239
  readonly projectConfig: ProjectConfig;
231
- /** 底层运行平台驱动适配契约 */
232
- readonly platform: RuntimePlatform;
233
- /** 当前包持久化存储实例 */
234
- readonly storage: RuntimeStorage;
235
- /** 全局持久化存储实例 */
236
- readonly globalStorage?: RuntimeStorage;
237
- /** 统一执行协调服务实例 */
238
- readonly executionService: ExecutionService;
239
- /** 预加载的 Action 定义映射表(短标识至定义) */
240
- readonly actionsMap: Map<string, ActionDefinition>;
240
+ /**
241
+ * 受信任内部调用方法(Host 或子任务执行主链调用入口)。
242
+ * 委托内部 ExecutionService 执行,确保全生命周期指标与事件不发生分裂。
243
+ */
244
+ startInvocation(actionId: string, input: JsonValue, context: InvocationContext): Promise<ExecutionTicket>;
241
245
  /** 获取当前包元数据信息 */
242
246
  info(options?: {
243
247
  exposeDebugInfo?: boolean;
@@ -251,13 +255,20 @@ export interface ActionDockApp {
251
255
  /** 静态查询并返回指定 Playbook 的规范内容与操作指南 */
252
256
  describePlaybook(id: string): Promise<PlaybookSpec>;
253
257
  /** 同步执行指定 Action 并等待终态结果(仅接受本包短标识) */
254
- runAction(id: string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionResult>;
258
+ runAction(id: string, input: JsonValue, options?: RunOptions): Promise<ExecutionResult>;
255
259
  /** 异步启动指定 Action 并立即返回任务执行票据(仅接受本包短标识) */
256
- startAction(id: string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionTicket>;
260
+ startAction(id: string, input: JsonValue, options?: RunOptions): Promise<ExecutionTicket>;
261
+ /** 查询任务执行记录列表 */
262
+ listRuns(options?: ListRunsOptions): Promise<RunRecord[]>;
257
263
  /** 查询指定运行标识的记录详情 */
258
264
  getRun(runId: string): Promise<RunRecord | undefined>;
259
265
  /** 取消指定在运行的任务 */
260
266
  cancelRun(runId: string, reason?: string): Promise<CancelResult>;
267
+ /** 清空历史任务运行记录 */
268
+ clearRuns(options?: {
269
+ actionId?: string;
270
+ status?: string;
271
+ }): Promise<number>;
261
272
  /** 订阅指定运行的事件流 */
262
273
  events(runId: string, options?: {
263
274
  after?: number | string;
@@ -293,8 +304,16 @@ export interface ActionDockApp {
293
304
  /** 清空指定持久化状态项 */
294
305
  clearState(options?: StateScopeOptions): Promise<number>;
295
306
  clearState(actionId: string, options?: StateScopeOptions): Promise<number>;
307
+ /** 列出当前包在存储中的状态条目(含完整元数据) */
308
+ listStateEntries?(options?: any): Promise<StateEntry[]>;
296
309
  /** 优雅关闭应用并收尾清理所有底层资源 */
297
310
  close(options?: {
298
311
  graceMs?: number;
299
312
  }): Promise<void>;
300
313
  }
314
+ /**
315
+ * 宿主托管专用内部运行时契约。
316
+ */
317
+ export interface HostManagedPackageRuntime extends PackageRuntime {
318
+ setActionInvoker(invoker?: ActionInvoker): void;
319
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 对 Action 摘要列表应用统一的检索过滤(标签、模糊关键词与标识前缀)。
3
+ *
4
+ * PackageRuntime 与 Host 两级列表查询的单一事实源:
5
+ * 两处过滤块逐字相同,收敛后调用方仅需在外层叠加各自的特有逻辑
6
+ * (Host 版在过滤前额外完成可见性筛选与跨包限定名改写)。
7
+ */
8
+ export function applyActionSummaryFilters(summaries, options) {
9
+ let results = summaries;
10
+ if (options?.tags && options.tags.length > 0) {
11
+ results = results.filter((s) => options.tags.every((t) => s.tags?.includes(t)));
12
+ }
13
+ if (options?.query) {
14
+ const q = options.query.toLowerCase();
15
+ results = results.filter((s) => s.id.toLowerCase().includes(q) ||
16
+ (s.description && s.description.toLowerCase().includes(q)));
17
+ }
18
+ if (options?.prefix) {
19
+ results = results.filter((s) => s.id.startsWith(options.prefix));
20
+ }
21
+ return results;
22
+ }
@@ -1,3 +1,3 @@
1
1
  export * from "./types.js";
2
2
  export * from "./node-fs.js";
3
- export * from "./default.js";
3
+ export * from "./node.js";
@@ -1,3 +1,3 @@
1
1
  export * from "./types.js";
2
2
  export * from "./node-fs.js";
3
- export * from "./default.js";
3
+ export * from "./node.js";
@@ -0,0 +1,48 @@
1
+ import type { ProcessAPI } from "@actiondock/sdk";
2
+ import { type Clock } from "../runtime/clock.js";
3
+ import { type ModuleLoader } from "../node/module-loader.js";
4
+ import { ProcessManager } from "../process/process-manager.js";
5
+ import type { ProcessDriver } from "../process/driver.js";
6
+ import { type SqliteDriver } from "../storage/index.js";
7
+ import type { FileSystem, RuntimePlatform, StorageFactory } from "./types.js";
8
+ /**
9
+ * Node 平台构建配置选项。
10
+ */
11
+ export interface NodePlatformOptions {
12
+ /** 平台名称覆盖(默认使用 node) */
13
+ name?: "node" | "test";
14
+ /** 自定义全局数据存储目录 */
15
+ dataDir?: string;
16
+ /** 自定义家目录路径 */
17
+ customHome?: string;
18
+ /** 文件系统安全沙箱根路径 */
19
+ rootDir?: string;
20
+ /** 自定义 SQLite 驱动工厂函数(必须返回满足同步契约的 SqliteDriver,默认实例化 NodeSqliteDriver) */
21
+ driverFactory?: (dbPath: string) => SqliteDriver;
22
+ /** 自定义进程执行驱动(默认依托基于 NodeProcessDriver 的 ProcessManager) */
23
+ process?: ProcessAPI;
24
+ /** 可选注入的底层进程驱动 */
25
+ processDriver?: ProcessDriver;
26
+ /** 可选注入的受管进程管理器 */
27
+ processManager?: ProcessManager;
28
+ /** 自定义源码加载驱动(默认实例化 NodeModuleLoader) */
29
+ modules?: ModuleLoader;
30
+ /** 自定义文件系统实现(默认实例化 NodeFileSystem) */
31
+ files?: FileSystem;
32
+ /** 自定义时钟驱动(默认实例化 SystemClock) */
33
+ clock?: Clock;
34
+ /** 自定义存储工厂(默认基于 NodeSqliteDriver 构造) */
35
+ storage?: StorageFactory;
36
+ }
37
+ /**
38
+ * 创建 Node 运行时平台实例。
39
+ * 组装 Node 原生核心组件:
40
+ * - NodeSqliteDriver 同步持久化存储驱动
41
+ * - NodeProcessDriver 原生进程驱动与 ProcessManager 受管进程引擎
42
+ * - NodeModuleLoader 原生源码加载器
43
+ * - NodeFileSystem 文件系统
44
+ * - SystemClock 系统时钟
45
+ *
46
+ * @param options 平台配置选项
47
+ */
48
+ export declare function createNodePlatform(options?: NodePlatformOptions): RuntimePlatform;
@@ -0,0 +1,96 @@
1
+ import { existsSync, mkdirSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+ import { SystemClock } from "../runtime/clock.js";
4
+ import { NodeModuleLoader } from "../node/module-loader.js";
5
+ import { NodeProcessDriver } from "../process/process-driver.js";
6
+ import { ProcessManager } from "../process/process-manager.js";
7
+ import { NodeSqliteDriver } from "../storage/sqlite-driver.js";
8
+ import { resolveDatabasePath, resolveGlobalDatabasePath, SqliteRuntimeStorage, } from "../storage/index.js";
9
+ import { NodeFileSystem } from "./node-fs.js";
10
+ function ensureDirectoryForDb(dbPath) {
11
+ if (dbPath !== ":memory:") {
12
+ const dir = dirname(dbPath);
13
+ if (!existsSync(dir)) {
14
+ try {
15
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
16
+ }
17
+ catch (err) {
18
+ if (err?.code === "EEXIST" || err?.code === "EISDIR") {
19
+ return;
20
+ }
21
+ throw new Error(`Failed to create data directory '${dir}' for database '${dbPath}': ${err?.message || String(err)}`, { cause: err });
22
+ }
23
+ }
24
+ }
25
+ }
26
+ /**
27
+ * 创建 Node 运行时平台实例。
28
+ * 组装 Node 原生核心组件:
29
+ * - NodeSqliteDriver 同步持久化存储驱动
30
+ * - NodeProcessDriver 原生进程驱动与 ProcessManager 受管进程引擎
31
+ * - NodeModuleLoader 原生源码加载器
32
+ * - NodeFileSystem 文件系统
33
+ * - SystemClock 系统时钟
34
+ *
35
+ * @param options 平台配置选项
36
+ */
37
+ export function createNodePlatform(options = {}) {
38
+ const platformName = options.name ?? "node";
39
+ const clock = options.clock ?? new SystemClock();
40
+ const files = options.files ?? new NodeFileSystem({ rootDir: options.rootDir });
41
+ const modules = options.modules ?? new NodeModuleLoader();
42
+ const processDriver = options.processDriver ?? new NodeProcessDriver();
43
+ const processManager = options.processManager ?? new ProcessManager({ driver: processDriver });
44
+ const process = options.process ??
45
+ processManager.forOwner({
46
+ tenantId: "default",
47
+ principalId: "default",
48
+ packageInstanceId: "default",
49
+ generationId: "default",
50
+ });
51
+ const createDriver = options.driverFactory ?? ((dbPath) => new NodeSqliteDriver(dbPath));
52
+ const storage = options.storage ?? {
53
+ createStorage(packageId, opts) {
54
+ const mergedOpts = {
55
+ customHome: options.customHome,
56
+ dataDir: options.dataDir,
57
+ ...opts,
58
+ };
59
+ const dbPath = resolveDatabasePath(packageId, mergedOpts);
60
+ ensureDirectoryForDb(dbPath);
61
+ return new SqliteRuntimeStorage({
62
+ dbPath,
63
+ packageId,
64
+ clock,
65
+ driver: createDriver(dbPath),
66
+ recoverOrphans: opts?.recoverOrphans === true,
67
+ });
68
+ },
69
+ createGlobalStorage(opts) {
70
+ const mergedOpts = {
71
+ customHome: options.customHome,
72
+ dataDir: options.dataDir,
73
+ ...opts,
74
+ };
75
+ const dbPath = mergedOpts.inMemory
76
+ ? ":memory:"
77
+ : resolveGlobalDatabasePath({ dataDir: mergedOpts.dataDir, customHome: mergedOpts.customHome });
78
+ ensureDirectoryForDb(dbPath);
79
+ return new SqliteRuntimeStorage({
80
+ dbPath,
81
+ packageId: "__global__",
82
+ clock,
83
+ driver: createDriver(dbPath),
84
+ recoverOrphans: opts?.recoverOrphans === true,
85
+ });
86
+ },
87
+ };
88
+ return {
89
+ name: platformName,
90
+ clock,
91
+ files,
92
+ modules,
93
+ process,
94
+ storage,
95
+ };
96
+ }
@@ -82,15 +82,6 @@ export interface StorageFactory {
82
82
  */
83
83
  createGlobalStorage(options?: GlobalStorageFactoryOptions): RuntimeStorage;
84
84
  }
85
- /**
86
- * 跨运行时 HTTP 服务启动工厂契约。
87
- */
88
- export interface HttpServerFactory {
89
- /**
90
- * 启动 HTTP 服务端实例。
91
- */
92
- launchHttpServer(options: any): Promise<any>;
93
- }
94
85
  /**
95
86
  * 运行时底层环境核心标准契约。
96
87
  * 提供统一的运行时契约,屏蔽宿主平台与测试沙箱环境的实现差异。
@@ -1,4 +1,5 @@
1
1
  import type { ControlGrant } from "@actiondock/sdk";
2
+ import { type ErrorCode } from "../errors.js";
2
3
  import type { ManagedProcessRecord, ProcessOwner } from "./managed-record.js";
3
4
  import type { StoredProcessRecord } from "./metadata-store.js";
4
5
  /**
@@ -97,7 +98,7 @@ export declare class ControlArbiter {
97
98
  * 禁止直接操作 acquireWaiters 数组。
98
99
  */
99
100
  revokeAllWaiters(proc: ManagedProcessRecord, reason: {
100
- code: string;
101
+ code: ErrorCode;
101
102
  message: string;
102
103
  }): void;
103
104
  /**
@@ -1,4 +1,3 @@
1
- import { randomUUID } from "node:crypto";
2
1
  import { ACCESS_DENIED, CONTROL_BUSY, CONTROL_EXPIRED, CONTROL_REVOKED, PROCESS_QUARANTINED, QUOTA_EXCEEDED, ProcessError, } from "../errors.js";
3
2
  /**
4
3
  * 控制权仲裁器。
@@ -103,7 +102,7 @@ export class ControlArbiter {
103
102
  */
104
103
  grantControl(proc, requestId, ttlMs, runId) {
105
104
  proc.controlEpoch += 1;
106
- const token = `tok_${proc.info.id}_${proc.controlEpoch}_${randomUUID().replace(/-/g, "")}`;
105
+ const token = `tok_${proc.info.id}_${proc.controlEpoch}_${crypto.randomUUID().replace(/-/g, "")}`;
107
106
  const expiresAt = new Date(Date.now() + ttlMs).toISOString();
108
107
  proc.info.control = "held";
109
108
  proc.currentGrant = {
@@ -3,6 +3,10 @@ import type { Capabilities, LaunchSpec } from "@actiondock/sdk";
3
3
  * 进程驱动实例底层控制句柄接口。
4
4
  */
5
5
  export interface ProcessDriverHandle {
6
+ /**
7
+ * 进程系统标识符(若底层为操作系统子进程)。
8
+ */
9
+ pid?: number;
6
10
  /**
7
11
  * 向受管进程标准输入通道写入原始字节数据。
8
12
  *
@@ -82,6 +86,8 @@ export declare function resolveProcessEnv(envConfig?: LaunchSpec["env"], hostEnv
82
86
  * 进程观察者接口,接收来自底层驱动的流输出与生命周期通知。
83
87
  */
84
88
  export interface ProcessObserver {
89
+ /** 期望关联的受管进程标识(若有) */
90
+ processId?: string;
85
91
  /**
86
92
  * 接收来自进程的输出数据。
87
93
  *
@@ -135,10 +141,6 @@ export interface ProcessDriver {
135
141
  * @param observer 进程生命周期与输出观察者
136
142
  */
137
143
  spawn(spec: LaunchSpec, observer: ProcessObserver): Promise<ProcessHandle>;
138
- /**
139
- * 兼容旧版基于 processId 派生新进程签名。
140
- */
141
- spawn(processId: string, spec: LaunchSpec, callbacks: ProcessDriverCallbacks): Promise<ProcessDriverHandle>;
142
144
  /**
143
145
  * 向受管进程标准输入写入字节数据。
144
146
  *
@@ -162,7 +164,6 @@ export interface ProcessDriver {
162
164
  * 优雅终止或强制终止底层进程。
163
165
  */
164
166
  terminate(handle: ProcessHandle, graceMs: number): Promise<void>;
165
- terminate(processId: string, graceMs: number): Promise<void>;
166
167
  /**
167
168
  * 销毁进程句柄并清理关联资源。
168
169
  */
@@ -174,12 +175,12 @@ export interface ProcessDriver {
174
175
  export declare class MemoryProcessDriver implements ProcessDriver {
175
176
  private capabilities;
176
177
  handles: Map<string, MemoryProcessDriverHandle>;
177
- spawnHook?: (processId: string, spec: LaunchSpec, callbacks: ProcessDriverCallbacks) => Promise<MemoryProcessDriverHandle | void> | MemoryProcessDriverHandle | void;
178
+ spawnHook?: (spec: LaunchSpec, observer: ProcessObserver) => Promise<MemoryProcessDriverHandle | void> | MemoryProcessDriverHandle | void;
178
179
  constructor(capabilities?: Partial<Capabilities>);
179
180
  getCapabilities(): Capabilities;
180
181
  setCapabilities(caps: Partial<Capabilities>): void;
181
- spawn(specOrProcessId: LaunchSpec | string, observerOrSpec: ProcessObserver | LaunchSpec, maybeCallbacks?: ProcessDriverCallbacks): Promise<any>;
182
- terminate(handleOrId: ProcessHandle | string, graceMs: number): Promise<void>;
182
+ spawn(spec: LaunchSpec, observer: ProcessObserver): Promise<ProcessHandle>;
183
+ terminate(handle: ProcessHandle, graceMs: number): Promise<void>;
183
184
  }
184
185
  /**
185
186
  * 内存模拟进程驱动句柄实现。
@@ -93,25 +93,15 @@ export class MemoryProcessDriver {
93
93
  setCapabilities(caps) {
94
94
  this.capabilities = { ...this.capabilities, ...caps };
95
95
  }
96
- async spawn(specOrProcessId, observerOrSpec, maybeCallbacks) {
97
- if (typeof specOrProcessId === "string") {
98
- const processId = specOrProcessId;
99
- const spec = observerOrSpec;
100
- const callbacks = maybeCallbacks;
101
- if (this.spawnHook) {
102
- const customHandle = await this.spawnHook(processId, spec, callbacks);
103
- if (customHandle) {
104
- this.handles.set(processId, customHandle);
105
- return customHandle;
106
- }
96
+ async spawn(spec, observer) {
97
+ const processId = observer.processId ?? `mem-${Math.random().toString(36).slice(2, 10)}`;
98
+ if (this.spawnHook) {
99
+ const customHandle = await this.spawnHook(spec, observer);
100
+ if (customHandle) {
101
+ this.handles.set(customHandle.id, customHandle);
102
+ return customHandle;
107
103
  }
108
- const handle = new MemoryProcessDriverHandle(processId, spec, callbacks);
109
- this.handles.set(processId, handle);
110
- return handle;
111
104
  }
112
- const spec = specOrProcessId;
113
- const observer = observerOrSpec;
114
- const processId = `mem-${Math.random().toString(36).slice(2, 10)}`;
115
105
  const callbacks = {
116
106
  onOutput(stream, data) {
117
107
  observer.output(stream, data);
@@ -130,11 +120,10 @@ export class MemoryProcessDriver {
130
120
  this.handles.set(processId, handle);
131
121
  return handle;
132
122
  }
133
- async terminate(handleOrId, graceMs) {
134
- const id = typeof handleOrId === "string" ? handleOrId : handleOrId.id;
135
- const handle = this.handles.get(id);
136
- if (handle) {
137
- await handle.terminate(graceMs);
123
+ async terminate(handle, graceMs) {
124
+ const instance = this.handles.get(handle.id);
125
+ if (instance) {
126
+ await instance.terminate(graceMs);
138
127
  }
139
128
  }
140
129
  }
@@ -11,3 +11,5 @@ export * from "./control-arbiter.js";
11
11
  export * from "./input-dispatcher.js";
12
12
  export * from "./process-manager.js";
13
13
  export * from "./context-process.js";
14
+ export * from "./process-driver.js";
15
+ export * from "./process-executor.js";
@@ -11,3 +11,5 @@ export * from "./control-arbiter.js";
11
11
  export * from "./input-dispatcher.js";
12
12
  export * from "./process-manager.js";
13
13
  export * from "./context-process.js";
14
+ export * from "./process-driver.js";
15
+ export * from "./process-executor.js";
@@ -1,5 +1,5 @@
1
1
  import type { ControlGrant, Limits, OperationReceipt, ProcessControlAction, ProcessInfo } from "@actiondock/sdk";
2
- import type { ProcessDriverHandle } from "./driver.js";
2
+ import type { ProcessDriverHandle, ProcessHandle } from "./driver.js";
3
3
  import type { ProcessRequestKey } from "./metadata-store.js";
4
4
  import type { ProcessOutputLog } from "./output-log.js";
5
5
  import type { EvictedOutputTombstone } from "./terminal-output-cache.js";
@@ -50,7 +50,7 @@ export interface ManagedProcessRecord {
50
50
  info: ProcessInfo;
51
51
  owner: ProcessOwner;
52
52
  scope: string;
53
- handle?: ProcessDriverHandle;
53
+ handle?: ProcessHandle & ProcessDriverHandle;
54
54
  outputLog: ProcessOutputLog;
55
55
  outputUnavailable?: boolean;
56
56
  outputTombstone?: EvictedOutputTombstone;