@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
@@ -0,0 +1,172 @@
1
+ import type { ActionDefinition, ActionRef, Logger, ProcessAPI, ProgressReporter } from "@actiondock/sdk";
2
+ import type { ProcessOwner } from "../process/index.js";
3
+ import { createPackageIdentity, type PackageIdentity } from "../runtime/identity.js";
4
+ export { createPackageIdentity };
5
+ export type { PackageIdentity };
6
+ export type { RunOptions } from "../service/types.js";
7
+ /**
8
+ * 构造默认进程归属所有者(ProcessOwner)的单一事实源工厂。
9
+ *
10
+ * 兜底语义:租户与主体标识缺失时回退 "default",包实例与代次标识缺失时回退
11
+ * 调用方提供的兜底值;全部五处默认 Owner 构造点(invocation、runner、runtime
12
+ * 上下文与进程执行器)必须统一经由本工厂,禁止散落字面量拷贝。
13
+ */
14
+ export declare function createDefaultProcessOwner(options?: {
15
+ /** 租户标识,缺省回退 "default" */
16
+ tenantId?: string;
17
+ /** 主体标识,缺省回退 "default" */
18
+ principalId?: string;
19
+ /** 包物理实例标识兜底值,缺省回退 "default" */
20
+ packageInstanceId?: string;
21
+ /** 快照代次标识兜底值,缺省回退 "default" */
22
+ generationId?: string;
23
+ }): ProcessOwner;
24
+ /**
25
+ * 内部调用方身份凭证(InvocationCaller)。
26
+ */
27
+ export interface InvocationCaller {
28
+ /** 调用方所在包标识 */
29
+ readonly packageId: string;
30
+ /** 调用方 Action 标识 */
31
+ readonly actionId: string;
32
+ /** 调用方运行 ID */
33
+ readonly runId?: string;
34
+ /** 调用方声明的 uses 列表 */
35
+ readonly declaredUses?: string[];
36
+ }
37
+ /**
38
+ * 内部调用上下文(InvocationContext)。
39
+ * 贯穿 Host -> Resolution -> PackageRuntime -> ExecutionService 的内部调用链路上下文。
40
+ */
41
+ export interface InvocationContext {
42
+ /** 本次执行的全局唯一运行标识 */
43
+ readonly runId: string;
44
+ /** 根运行标识(调用链起点) */
45
+ readonly rootRunId: string;
46
+ /** 直接父运行标识(嵌套子调用时关联) */
47
+ readonly parentRunId?: string;
48
+ /** 调用方上下文(若为嵌套/跨包调用) */
49
+ readonly caller?: InvocationCaller;
50
+ /** 调用栈数组快照(用于环路检测与调用深度限制) */
51
+ readonly callStack: readonly string[];
52
+ /** 目标包物理与快照身份标识 */
53
+ readonly package: PackageIdentity;
54
+ /** 取消信号 */
55
+ readonly signal: AbortSignal;
56
+ /** 超时毫秒数 */
57
+ readonly timeoutMs?: number;
58
+ /** 配置覆盖项 */
59
+ readonly config?: Record<string, unknown>;
60
+ /** 幂等请求标识 */
61
+ readonly requestId?: string;
62
+ /** 租户标识 */
63
+ readonly tenantId?: string;
64
+ /** 主体标识 */
65
+ readonly principalId?: string;
66
+ /** 执行宿主会话标识 */
67
+ readonly hostSessionId?: string;
68
+ /** 最大调用深度覆盖 */
69
+ readonly maxCallDepth?: number;
70
+ /** 日志记录器 */
71
+ readonly logger?: Logger;
72
+ /** 进度报告器 */
73
+ readonly progress?: ProgressReporter;
74
+ /** 进程执行器 */
75
+ readonly process?: ProcessAPI;
76
+ /** 进程属主身份 */
77
+ readonly owner?: ProcessOwner;
78
+ }
79
+ /**
80
+ * 内部调用上下文选项契约。
81
+ * 强制要求提供确定的 PackageIdentity,禁止隐式兜底 mock 默认包。
82
+ */
83
+ export interface CreateInvocationContextOptions extends Omit<Partial<InvocationContext>, "package"> {
84
+ /** 目标包物理与快照身份标识(必填单一事实源) */
85
+ package: PackageIdentity;
86
+ }
87
+ /**
88
+ * 构造合法的内部调用上下文(InvocationContext)。
89
+ * 供测试或内部直接调用执行服务时便捷装配上下文凭据。
90
+ */
91
+ export declare function createInvocationContext(options: CreateInvocationContextOptions): InvocationContext;
92
+ /**
93
+ * 构造受信任的根调用上下文选项。
94
+ */
95
+ export interface CreateRootInvocationContextOptions {
96
+ /** 目标包物理与快照身份标识(必填单一事实源) */
97
+ targetPackage: PackageIdentity;
98
+ /** 可选的初始调用栈(根调用通常为 [rootKey]) */
99
+ callStack?: readonly string[];
100
+ /** 外部传入的 AbortSignal 取消信号 */
101
+ signal?: AbortSignal;
102
+ /** 最大超时时间(毫秒) */
103
+ timeoutMs?: number;
104
+ /** 执行级临时配置覆盖字典 */
105
+ config?: Record<string, unknown>;
106
+ /** 幂等请求标识 */
107
+ requestId?: string;
108
+ /** 执行宿主会话标识 */
109
+ hostSessionId?: string;
110
+ /** 最大调用嵌套深度限制 */
111
+ maxCallDepth?: number;
112
+ /** 外部进程执行器注入 */
113
+ process?: ProcessAPI;
114
+ /** 租户标识 */
115
+ tenantId?: string;
116
+ /** 主体标识 */
117
+ principalId?: string;
118
+ /** 日志记录器 */
119
+ logger?: Logger;
120
+ /** 进度报告器 */
121
+ progress?: ProgressReporter;
122
+ /** 显式执行归属所有者契约 */
123
+ owner?: ProcessOwner;
124
+ }
125
+ /**
126
+ * 构造合法的受信任根调用上下文(Root InvocationContext)。
127
+ * 在 Host 服务边界装配,严格保证无父级调用血缘(parentRunId 为 undefined),
128
+ * 根运行 ID 等同于自身运行 ID,且仅透传受信任参数。
129
+ *
130
+ * 实现委托 createInvocationContext 单一事实源:不传入 runId/rootRunId/parentRunId/caller,
131
+ * 由公共构造逻辑兜底生成 runId 并令 rootRunId 收敛为自身 runId;随后显式覆写
132
+ * parentRunId 与 caller 为 undefined,并按根调用契约挑选字段,保持无血缘血缘字段的键序不变。
133
+ */
134
+ export declare function createRootInvocationContext(options: CreateRootInvocationContextOptions): InvocationContext;
135
+ /**
136
+ * Action 执行上下文(ActionExecutionContext)。
137
+ * ActionRunner 启动单次 Action 执行时内部装配的完整上下文状态。
138
+ */
139
+ export interface ActionExecutionContext {
140
+ /** 运行 ID */
141
+ readonly runId: string;
142
+ /** 根运行 ID */
143
+ readonly rootRunId: string;
144
+ /** 父运行 ID */
145
+ readonly parentRunId?: string;
146
+ /** 当前执行所属包标识 */
147
+ readonly packageIdentity: PackageIdentity;
148
+ /** 目标 Action 标识 */
149
+ readonly targetActionId: string;
150
+ /** 输入数据 */
151
+ readonly input: unknown;
152
+ /** 目标 Action 定义(若已解析就绪) */
153
+ readonly action?: ActionDefinition;
154
+ /** 调用栈数组快照 */
155
+ readonly callStack: readonly string[];
156
+ /** 取消中断控制器 */
157
+ readonly controller: AbortController;
158
+ /** 执行开始时间戳 */
159
+ readonly startedAt: string;
160
+ /** 生效的进程执行器 */
161
+ readonly effectiveProcess?: ProcessAPI;
162
+ /** 进程属主信息 */
163
+ readonly owner: ProcessOwner;
164
+ /** 日志记录器 */
165
+ readonly logger?: Logger;
166
+ /** 进度报告器 */
167
+ readonly progress?: ProgressReporter;
168
+ /** 配置覆盖项 */
169
+ readonly configOverrides?: Record<string, unknown>;
170
+ /** 嵌套子调用委托函数 */
171
+ readonly actionInvoker?: (childAction: ActionRef | string, childInput: unknown, callerRunId?: string) => Promise<unknown>;
172
+ }
@@ -0,0 +1,97 @@
1
+ import { createPackageIdentity } from "../runtime/identity.js";
2
+ export { createPackageIdentity };
3
+ /**
4
+ * 构造默认进程归属所有者(ProcessOwner)的单一事实源工厂。
5
+ *
6
+ * 兜底语义:租户与主体标识缺失时回退 "default",包实例与代次标识缺失时回退
7
+ * 调用方提供的兜底值;全部五处默认 Owner 构造点(invocation、runner、runtime
8
+ * 上下文与进程执行器)必须统一经由本工厂,禁止散落字面量拷贝。
9
+ */
10
+ export function createDefaultProcessOwner(options) {
11
+ return {
12
+ tenantId: options?.tenantId || "default",
13
+ principalId: options?.principalId || "default",
14
+ packageInstanceId: options?.packageInstanceId || "default",
15
+ generationId: options?.generationId || "default",
16
+ };
17
+ }
18
+ /**
19
+ * 构造合法的内部调用上下文(InvocationContext)。
20
+ * 供测试或内部直接调用执行服务时便捷装配上下文凭据。
21
+ */
22
+ export function createInvocationContext(options) {
23
+ const runId = options.runId ?? crypto.randomUUID();
24
+ const rootRunId = options.rootRunId ?? runId;
25
+ const pkg = options.package;
26
+ return {
27
+ runId,
28
+ rootRunId,
29
+ parentRunId: options.parentRunId,
30
+ caller: options.caller,
31
+ callStack: options.callStack ? [...options.callStack] : [],
32
+ package: pkg,
33
+ signal: options.signal ?? new AbortController().signal,
34
+ timeoutMs: options.timeoutMs,
35
+ config: options.config,
36
+ requestId: options.requestId,
37
+ tenantId: options.tenantId,
38
+ principalId: options.principalId,
39
+ hostSessionId: options.hostSessionId,
40
+ maxCallDepth: options.maxCallDepth,
41
+ logger: options.logger,
42
+ progress: options.progress,
43
+ process: options.process,
44
+ owner: options.owner ??
45
+ createDefaultProcessOwner({
46
+ tenantId: options.tenantId,
47
+ principalId: options.principalId,
48
+ packageInstanceId: pkg.instanceId,
49
+ generationId: pkg.generation,
50
+ }),
51
+ };
52
+ }
53
+ /**
54
+ * 构造合法的受信任根调用上下文(Root InvocationContext)。
55
+ * 在 Host 服务边界装配,严格保证无父级调用血缘(parentRunId 为 undefined),
56
+ * 根运行 ID 等同于自身运行 ID,且仅透传受信任参数。
57
+ *
58
+ * 实现委托 createInvocationContext 单一事实源:不传入 runId/rootRunId/parentRunId/caller,
59
+ * 由公共构造逻辑兜底生成 runId 并令 rootRunId 收敛为自身 runId;随后显式覆写
60
+ * parentRunId 与 caller 为 undefined,并按根调用契约挑选字段,保持无血缘血缘字段的键序不变。
61
+ */
62
+ export function createRootInvocationContext(options) {
63
+ const base = createInvocationContext({
64
+ package: options.targetPackage,
65
+ callStack: options.callStack,
66
+ signal: options.signal,
67
+ timeoutMs: options.timeoutMs,
68
+ config: options.config,
69
+ requestId: options.requestId,
70
+ hostSessionId: options.hostSessionId,
71
+ maxCallDepth: options.maxCallDepth,
72
+ logger: options.logger,
73
+ progress: options.progress,
74
+ process: options.process,
75
+ owner: options.owner,
76
+ tenantId: options.tenantId,
77
+ principalId: options.principalId,
78
+ });
79
+ return {
80
+ runId: base.runId,
81
+ rootRunId: base.rootRunId,
82
+ parentRunId: undefined,
83
+ caller: undefined,
84
+ callStack: base.callStack,
85
+ package: base.package,
86
+ signal: base.signal,
87
+ timeoutMs: base.timeoutMs,
88
+ config: base.config,
89
+ requestId: base.requestId,
90
+ hostSessionId: base.hostSessionId,
91
+ maxCallDepth: base.maxCallDepth,
92
+ logger: base.logger,
93
+ progress: base.progress,
94
+ process: base.process,
95
+ owner: base.owner,
96
+ };
97
+ }
@@ -35,14 +35,6 @@ export declare class DiagnosticForwarder {
35
35
  private truncated;
36
36
  private attachedStreams;
37
37
  constructor(options?: DiagnosticForwarderOptions);
38
- /**
39
- * 是否已达到上限并处于截断状态。
40
- */
41
- get isTruncated(): boolean;
42
- /**
43
- * 已成功转发的累计字节数。
44
- */
45
- get bytesEmitted(): number;
46
38
  /**
47
39
  * 绑定并监听可读流(如 childProcess.stdout 或 childProcess.stderr)。
48
40
  *
@@ -58,8 +50,4 @@ export declare class DiagnosticForwarder {
58
50
  * 解绑所有已连接的流。
59
51
  */
60
52
  detachAll(): void;
61
- /**
62
- * 重置计数器与截断标志。
63
- */
64
- reset(): void;
65
53
  }
@@ -25,18 +25,6 @@ export class DiagnosticForwarder {
25
25
  this.prefix = options.prefix ?? "";
26
26
  this.onTruncated = options.onTruncated;
27
27
  }
28
- /**
29
- * 是否已达到上限并处于截断状态。
30
- */
31
- get isTruncated() {
32
- return this.truncated;
33
- }
34
- /**
35
- * 已成功转发的累计字节数。
36
- */
37
- get bytesEmitted() {
38
- return this.totalBytesEmitted;
39
- }
40
28
  /**
41
29
  * 绑定并监听可读流(如 childProcess.stdout 或 childProcess.stderr)。
42
30
  *
@@ -117,13 +105,4 @@ export class DiagnosticForwarder {
117
105
  }
118
106
  this.attachedStreams.clear();
119
107
  }
120
- /**
121
- * 重置计数器与截断标志。
122
- */
123
- reset() {
124
- this.totalBytesEmitted = 0;
125
- this.bytesInCurrentWindow = 0;
126
- this.windowStartMs = Date.now();
127
- this.truncated = false;
128
- }
129
108
  }
@@ -1,12 +1,12 @@
1
- import type { ActionDockTarget } from "../target/types.js";
1
+ import type { ActionDockService } from "../service/types.js";
2
2
  /**
3
- * 在 Host 子进程中启动 Node IPC 服务,向父进程暴露 ActionDockTarget 门面能力。
3
+ * 在 Host 子进程中启动 Node IPC 服务,向父进程暴露 ActionDockService 门面能力。
4
4
  *
5
5
  * 跨进程取消链路:监督进程序列化执行选项时把 AbortSignal 替换为占位标记,
6
6
  * 本侧反序列化时识别标记并重建 AbortController 传入目标调用,同时维护
7
7
  * 调用 id 到控制器的映射;收到 abort 消息时触发对应控制器中止,
8
8
  * 调用完成后清理映射,确保取消信号全链路透传。
9
9
  *
10
- * @param target 已构造好的 ActionDockTarget 实例
10
+ * @param service 已构造好的 ActionDockService 实例
11
11
  */
12
- export declare function serveParentIpc(target: ActionDockTarget): Promise<void>;
12
+ export declare function serveParentIpc(service: ActionDockService): Promise<void>;
package/dist/ipc/host.js CHANGED
@@ -1,47 +1,49 @@
1
- import { TARGET_CAPABILITY_UNAVAILABLE } from "../target/types.js";
2
- import { hasIpcSignalMarker, IPC_SIGNAL_MARKER } from "./target.js";
1
+ import { ActionDockError, CAPABILITY_UNAVAILABLE, SERVICE_ERROR } from "../errors.js";
2
+ import { hasIpcSignalMarker, IPC_SIGNAL_MARKER } from "./service.js";
3
3
  /**
4
- * IPC 通道允许反射调用的目标方法白名单。
4
+ * IPC 通道方法分发表:方法名到目标调用的唯一事实源。
5
5
  *
6
- * 严格对齐 ActionDockTarget 公共接口方法名集合:白名单之外的方法一律拒绝,
7
- * 防止 IPC 消息通道触达任意内部属性或危险方法(如 close 之外的私有能力)。
6
+ * 严格对齐 ActionDockService 公共方法集合:表之外的方法一律拒绝,
7
+ * 防止 IPC 消息通道触达任意内部属性或危险方法。
8
+ * 白名单即分发表的键集合,杜绝两份清单重复维护漂移。
8
9
  */
9
- const IPC_ALLOWED_METHODS = new Set([
10
- "info",
11
- "listPackages",
12
- "listActions",
13
- "describeAction",
14
- "listPlaybooks",
15
- "describePlaybook",
16
- "runAction",
17
- "startAction",
18
- "listRuns",
19
- "getRun",
20
- "cancelRun",
21
- "clearRuns",
22
- "events",
23
- "getConfig",
24
- "setConfig",
25
- "deleteConfig",
26
- "listConfig",
27
- "getState",
28
- "setState",
29
- "deleteState",
30
- "listStateKeys",
31
- "clearState",
32
- "listStateEntries",
33
- ]);
10
+ const IPC_METHOD_HANDLERS = {
11
+ info: async (service) => service.info(),
12
+ listPackages: async (service) => service.discovery.listPackages(),
13
+ listActions: async (service, a) => service.discovery.listActions(a[0]),
14
+ describeAction: async (service, a) => service.discovery.describeAction(a[0]),
15
+ listPlaybooks: async (service, a) => service.discovery.listPlaybooks(a[0]),
16
+ describePlaybook: async (service, a) => service.discovery.describePlaybook(a[0]),
17
+ runAction: async (service, a) => service.execution.run(a[0], a[1], a[2]),
18
+ startAction: async (service, a) => service.execution.start(a[0], a[1], a[2]),
19
+ listRuns: async (service, a) => service.runs.list(a[0]),
20
+ getRun: async (service, a) => service.runs.get(a[0]),
21
+ cancelRun: async (service, a) => service.runs.cancel(a[0], a[1]),
22
+ clearRuns: async (service, a) => service.runs.clear ? await service.runs.clear(a[0]) : 0,
23
+ getConfig: async (service, a) => service.management?.config.get(a[0], a[1]),
24
+ setConfig: async (service, a) => service.management?.config.set(a[0], a[1], a[2]),
25
+ deleteConfig: async (service, a) => service.management?.config.delete(a[0], a[1]),
26
+ listConfig: async (service, a) => service.management?.config.list(a[0]),
27
+ getState: async (service, a) => service.management?.state.get(a[0], a[1], a[2], a[3]),
28
+ setState: async (service, a) => service.management?.state.set(a[0], a[1], a[2], a[3], a[4]),
29
+ deleteState: async (service, a) => service.management?.state.delete(a[0], a[1], a[2], a[3]),
30
+ listStateKeys: async (service, a) => service.management?.state.list(a[0], a[1], a[2]),
31
+ clearState: async (service, a) => service.management?.state.clear(a[0], a[1], a[2]),
32
+ listStateEntries: async (service, a) => service.management?.state.listEntries
33
+ ? await service.management.state.listEntries(a[0], a[1])
34
+ : [],
35
+ };
34
36
  /**
35
- * 在 Host 子进程中启动 Node IPC 服务,向父进程暴露 ActionDockTarget 门面能力。
37
+ * 在 Host 子进程中启动 Node IPC 服务,向父进程暴露 ActionDockService 门面能力。
36
38
  *
37
39
  * 跨进程取消链路:监督进程序列化执行选项时把 AbortSignal 替换为占位标记,
38
40
  * 本侧反序列化时识别标记并重建 AbortController 传入目标调用,同时维护
39
41
  * 调用 id 到控制器的映射;收到 abort 消息时触发对应控制器中止,
40
42
  * 调用完成后清理映射,确保取消信号全链路透传。
41
43
  *
42
- * @param target 已构造好的 ActionDockTarget 实例
44
+ * @param service 已构造好的 ActionDockService 实例
43
45
  */
44
- export async function serveParentIpc(target) {
46
+ export async function serveParentIpc(service) {
45
47
  if (!process.send) {
46
48
  // 若当前未以 IPC 模式运行,直接退出
47
49
  return;
@@ -52,7 +54,7 @@ export async function serveParentIpc(target) {
52
54
  return;
53
55
  isClosing = true;
54
56
  try {
55
- await target.close();
57
+ await service.close();
56
58
  }
57
59
  catch {
58
60
  // 忽略关闭异常
@@ -97,19 +99,14 @@ export async function serveParentIpc(target) {
97
99
  const callMsg = msg;
98
100
  const { id, method, args } = callMsg;
99
101
  try {
100
- // 白名单校验:仅允许 ActionDockTarget 公共接口方法,阻止任意方法反射调用
101
- if (typeof method !== "string" || !IPC_ALLOWED_METHODS.has(method)) {
102
- const err = new Error(`Target method '${method}' is not allowed over IPC (not in ActionDockTarget public interface)`);
103
- err.code = TARGET_CAPABILITY_UNAVAILABLE;
104
- throw err;
105
- }
106
- const fn = target[method];
107
- if (typeof fn !== "function") {
108
- throw new Error(`Target method '${method}' not found`);
102
+ // 白名单校验:仅允许分发表内方法,阻止任意方法反射调用
103
+ const handler = typeof method === "string" ? IPC_METHOD_HANDLERS[method] : undefined;
104
+ if (!handler) {
105
+ throw new ActionDockError(CAPABILITY_UNAVAILABLE, `Target method '${method}' is not allowed over IPC`);
109
106
  }
110
107
  // 反序列化执行选项:识别取消信号占位标记并重建控制器接入取消链路
111
- const revivedArgs = (args || []).map((arg) => reviveIpcSignal(id, arg));
112
- const result = await fn.apply(target, revivedArgs);
108
+ const a = (args || []).map((arg) => reviveIpcSignal(id, arg));
109
+ const result = await handler(service, a);
113
110
  const response = {
114
111
  id,
115
112
  type: "response",
@@ -126,7 +123,7 @@ export async function serveParentIpc(target) {
126
123
  type: "response",
127
124
  ok: false,
128
125
  error: {
129
- code: err?.code || "TARGET_ERROR",
126
+ code: err?.code || SERVICE_ERROR,
130
127
  message: err?.message || String(err),
131
128
  stack: err?.stack,
132
129
  details: err?.details,
@@ -162,7 +159,7 @@ export async function serveParentIpc(target) {
162
159
  }
163
160
  }
164
161
  else {
165
- // 向后兼容:旧版本对端可能推送未知消息类型,防御性忽略并记录诊断,不中断通道
162
+ // 防御性忽略未知消息类型并记录诊断,不中断通道
166
163
  process.stderr.write(`[IPC Host] Ignoring unknown IPC message type: ${JSON.stringify(msg.type)}\n`);
167
164
  }
168
165
  });
@@ -1,4 +1,4 @@
1
1
  export * from "./types.js";
2
2
  export * from "./diagnostic.js";
3
3
  export * from "./host.js";
4
- export * from "./target.js";
4
+ export * from "./service.js";
package/dist/ipc/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from "./types.js";
2
2
  export * from "./diagnostic.js";
3
3
  export * from "./host.js";
4
- export * from "./target.js";
4
+ export * from "./service.js";
@@ -0,0 +1,40 @@
1
+ import { type ChildProcess } from "node:child_process";
2
+ import type { PackageInfo } from "../package/types.js";
3
+ import type { ActionDockService, ConfigPort, DiscoveryPort, ExecutionPort, RunsPort, StatePort } from "../service/types.js";
4
+ import type { IpcServiceOptions } from "./types.js";
5
+ /**
6
+ * 跨进程取消信号占位标记字段名。
7
+ * AbortSignal 不可序列化,序列化 options 时把 signal 字段替换为该标记,
8
+ * 宿主侧识别后重建 AbortController 并接入 abort 消息通知链路。
9
+ */
10
+ export declare const IPC_SIGNAL_MARKER = "__ipcSignal";
11
+ /**
12
+ * 判断执行选项中是否携带跨进程取消信号占位标记。
13
+ */
14
+ export declare function hasIpcSignalMarker(value: unknown): value is Record<string, unknown>;
15
+ /**
16
+ * 基于 Node IPC 监督进程通信通道的 ActionDockService 实现。
17
+ * 遵循标准 Service Ports 体系,隔离子进程生命周期并暴露结构化服务端口。
18
+ */
19
+ export declare class IpcActionDockService implements ActionDockService {
20
+ private child;
21
+ private forwarder;
22
+ private pendingCalls;
23
+ private isClosed;
24
+ private exitError?;
25
+ private readyPromise;
26
+ readonly discovery: DiscoveryPort;
27
+ readonly execution: ExecutionPort;
28
+ readonly runs: RunsPort;
29
+ readonly management?: {
30
+ config: ConfigPort;
31
+ state: StatePort;
32
+ };
33
+ constructor(options: IpcServiceOptions);
34
+ private callRemote;
35
+ private sendAbort;
36
+ info(): Promise<PackageInfo[]>;
37
+ get process(): ChildProcess;
38
+ waitReady(): Promise<void>;
39
+ close(): Promise<void>;
40
+ }