@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
@@ -0,0 +1,157 @@
1
+ import { type ErrorCode } from "../errors.js";
2
+ import type { PackageGraph } from "../catalog/graph.js";
3
+ /**
4
+ * 调用治理策略初始化选项。
5
+ */
6
+ export interface InvocationPolicyOptions {
7
+ /** 最大调用嵌套深度限制(默认 16) */
8
+ maxCallDepth?: number;
9
+ /** 单个根任务下最大并发活跃子任务数(默认 64) */
10
+ maxSubRuns?: number;
11
+ }
12
+ /**
13
+ * 根调用可见性上下文。
14
+ */
15
+ export interface RootVisibilityContext {
16
+ /** 宿主公开暴露的包标识集合 */
17
+ hostPublicPackageIds: ReadonlySet<string>;
18
+ /** 包依赖拓扑图 */
19
+ graph?: PackageGraph;
20
+ }
21
+ /**
22
+ * 调用方声明规范契约。
23
+ */
24
+ export interface CallerActionInfo {
25
+ packageId: string;
26
+ actionId: string;
27
+ declaredUses?: string[];
28
+ }
29
+ /**
30
+ * 目标 Action 规范契约。
31
+ */
32
+ export interface TargetActionInfo {
33
+ packageId: string;
34
+ actionId: string;
35
+ }
36
+ /**
37
+ * 调用治理策略错误描述。
38
+ */
39
+ export interface PolicyError {
40
+ code: ErrorCode;
41
+ message: string;
42
+ details?: Record<string, unknown>;
43
+ }
44
+ /**
45
+ * 环路检测结果。
46
+ */
47
+ export interface CycleCheckResult {
48
+ callKey: string;
49
+ error?: PolicyError;
50
+ }
51
+ /**
52
+ * 全局统一调用治理策略服务(InvocationPolicy)。
53
+ *
54
+ * 铁律 5 单一事实源:统一负责 root visibility、caller -> callee authorization、
55
+ * uses 检查、max call depth、cycle detection、subrun quota 与 lineage policy。
56
+ * 彻底消除 Host、ExecutionService 与 ActionRunner 中分散重复的检查逻辑。
57
+ */
58
+ export declare class InvocationPolicy {
59
+ readonly maxCallDepth: number;
60
+ readonly maxSubRuns: number;
61
+ private readonly activeSubRunsPerRoot;
62
+ private visibilityContext?;
63
+ constructor(options?: InvocationPolicyOptions);
64
+ /**
65
+ * 设置路由可见性上下文。
66
+ */
67
+ setVisibilityContext(context?: RootVisibilityContext): void;
68
+ /**
69
+ * 严格断言根调用可见性(Root Visibility Assertion)。
70
+ * 若不可见则抛出 ActionDockError(UNDECLARED_ACTION_DEPENDENCY, ...)。
71
+ */
72
+ assertRootVisibility(resolved: {
73
+ package: {
74
+ id: string;
75
+ };
76
+ ref: {
77
+ actionId: string;
78
+ };
79
+ }, context?: RootVisibilityContext): void;
80
+ /**
81
+ * 根调用可见性判定与鉴权(Root Visibility Policy)。
82
+ *
83
+ * 判定规则:
84
+ * - 宿主公开注册的包(直接依赖包或显式声明包)允许根调用;
85
+ * - 传递依赖包必须经由可见 Playbook 委托授权,否则拦截并返回 UNDECLARED_ACTION_DEPENDENCY。
86
+ *
87
+ * @param targetPackageId 目标包标识
88
+ * @param targetActionId 目标 Action 标识
89
+ * @param context 路由可见性上下文
90
+ * @returns 若拦截返回标准 RuntimeError,通过则返回 undefined
91
+ */
92
+ checkRootVisibility(targetPackageId: string, targetActionId: string, context: RootVisibilityContext): PolicyError | undefined;
93
+ /**
94
+ * 调用方至目标动作 uses 依赖声明授权校验(Caller -> Callee Authorization & Uses Policy)。
95
+ *
96
+ * 判定规则:
97
+ * - 同包内部 Action 互调自然合法,豁免 uses 声明;
98
+ * - 跨包调用必须在调用方 Action 的 uses 声明列表中显式声明目标(完全限定名、通配符或包名),
99
+ * 或经由 PackageGraph.canCascadeCall 裁决通过;未声明直接拦截。
100
+ *
101
+ * @param caller 调用方 Action 标识与声明上下文
102
+ * @param target 目标 Action 标识
103
+ * @param graph 可选的包依赖拓扑图
104
+ * @returns 若鉴权未通过返回标准 RuntimeError,通过则返回 undefined
105
+ */
106
+ checkUsesAuthorization(caller: CallerActionInfo, target: TargetActionInfo, graph?: PackageGraph): PolicyError | undefined;
107
+ /**
108
+ * 调用嵌套最大深度限制校验(Max Call Depth Policy)。
109
+ *
110
+ * 超限时返回标准 ACTION_CALL_CYCLE 错误。
111
+ *
112
+ * @param callStack 当前已累积的调用栈切片
113
+ * @param targetActionId 欲调用的目标 Action 标识
114
+ * @param maxDepthOverride 临时执行覆盖的最大深度限制
115
+ * @returns 超限错误或 undefined
116
+ */
117
+ checkCallDepth(callStack: readonly string[], targetActionId: string, maxDepthOverride?: number): PolicyError | undefined;
118
+ /**
119
+ * 调用链环路死锁检测(Cycle Detection Policy)。
120
+ *
121
+ * 计算目标调用键并在历史调用栈中执行检测,杜绝 A -> B -> A 形成死锁。
122
+ * 命中环路时返回 ACTION_CALL_CYCLE 错误。
123
+ *
124
+ * @param callStack 当前已累积的调用栈切片
125
+ * @param targetActionId 欲调用的目标 Action 标识
126
+ * @param targetPackageId 目标 Action 所属包标识
127
+ * @param currentPackageId 当前执行发起方包标识
128
+ * @returns 包含规范化 callKey 与可选错误的结构体
129
+ */
130
+ checkCycle(callStack: readonly string[], targetActionId: string, targetPackageId?: string, currentPackageId?: string): CycleCheckResult;
131
+ /**
132
+ * 并发活跃子任务配额检查(Sub-Run Quota Policy)。
133
+ *
134
+ * 针对同源 rootRunId 限制派生的并发子任务上限,防止资源耗尽。
135
+ *
136
+ * @param rootRunId 根运行标识符
137
+ * @returns 超限错误或 undefined
138
+ */
139
+ checkSubRunQuota(rootRunId: string): PolicyError | undefined;
140
+ /**
141
+ * 申请子任务并发配额槽位。
142
+ *
143
+ * @param rootRunId 根运行标识符
144
+ * @returns 是否成功获取槽位(若已达上限返回 false)
145
+ */
146
+ acquireSubRun(rootRunId: string): boolean;
147
+ /**
148
+ * 释放已申请的子任务并发配额槽位。
149
+ *
150
+ * @param rootRunId 根运行标识符
151
+ */
152
+ releaseSubRun(rootRunId: string): void;
153
+ /**
154
+ * 获取指定根运行当前的活跃并发子任务计数。
155
+ */
156
+ getActiveSubRuns(rootRunId: string): number;
157
+ }
@@ -0,0 +1,231 @@
1
+ import { ACTION_CALL_CYCLE, ACTION_SUBRUN_LIMIT, UNDECLARED_ACTION_DEPENDENCY, ActionDockError, } from "../errors.js";
2
+ import { isUsesDeclared } from "../catalog/graph.js";
3
+ /**
4
+ * 全局统一调用治理策略服务(InvocationPolicy)。
5
+ *
6
+ * 铁律 5 单一事实源:统一负责 root visibility、caller -> callee authorization、
7
+ * uses 检查、max call depth、cycle detection、subrun quota 与 lineage policy。
8
+ * 彻底消除 Host、ExecutionService 与 ActionRunner 中分散重复的检查逻辑。
9
+ */
10
+ export class InvocationPolicy {
11
+ maxCallDepth;
12
+ maxSubRuns;
13
+ activeSubRunsPerRoot = new Map();
14
+ visibilityContext;
15
+ constructor(options = {}) {
16
+ this.maxCallDepth = options.maxCallDepth ?? 16;
17
+ this.maxSubRuns = options.maxSubRuns ?? 64;
18
+ }
19
+ /**
20
+ * 设置路由可见性上下文。
21
+ */
22
+ setVisibilityContext(context) {
23
+ this.visibilityContext = context;
24
+ }
25
+ /**
26
+ * 严格断言根调用可见性(Root Visibility Assertion)。
27
+ * 若不可见则抛出 ActionDockError(UNDECLARED_ACTION_DEPENDENCY, ...)。
28
+ */
29
+ assertRootVisibility(resolved, context) {
30
+ const ctx = context ?? this.visibilityContext;
31
+ if (!ctx) {
32
+ return;
33
+ }
34
+ const error = this.checkRootVisibility(resolved.package.id, resolved.ref.actionId, ctx);
35
+ if (error) {
36
+ throw new ActionDockError(error.code, error.message, error.details);
37
+ }
38
+ }
39
+ /**
40
+ * 根调用可见性判定与鉴权(Root Visibility Policy)。
41
+ *
42
+ * 判定规则:
43
+ * - 宿主公开注册的包(直接依赖包或显式声明包)允许根调用;
44
+ * - 传递依赖包必须经由可见 Playbook 委托授权,否则拦截并返回 UNDECLARED_ACTION_DEPENDENCY。
45
+ *
46
+ * @param targetPackageId 目标包标识
47
+ * @param targetActionId 目标 Action 标识
48
+ * @param context 路由可见性上下文
49
+ * @returns 若拦截返回标准 RuntimeError,通过则返回 undefined
50
+ */
51
+ checkRootVisibility(targetPackageId, targetActionId, context) {
52
+ const isPublic = context.hostPublicPackageIds.has(targetPackageId);
53
+ if (isPublic) {
54
+ return undefined;
55
+ }
56
+ if (context.graph && !context.graph.canRootCall(targetPackageId, targetActionId)) {
57
+ return {
58
+ code: UNDECLARED_ACTION_DEPENDENCY,
59
+ message: `Root call to action '${targetPackageId}/${targetActionId}' is not allowed: package '${targetPackageId}' is not declared as a direct dependency in actiondock.json and is not delegated by a visible playbook`,
60
+ details: { target: `${targetPackageId}/${targetActionId}` },
61
+ };
62
+ }
63
+ return undefined;
64
+ }
65
+ /**
66
+ * 调用方至目标动作 uses 依赖声明授权校验(Caller -> Callee Authorization & Uses Policy)。
67
+ *
68
+ * 判定规则:
69
+ * - 同包内部 Action 互调自然合法,豁免 uses 声明;
70
+ * - 跨包调用必须在调用方 Action 的 uses 声明列表中显式声明目标(完全限定名、通配符或包名),
71
+ * 或经由 PackageGraph.canCascadeCall 裁决通过;未声明直接拦截。
72
+ *
73
+ * @param caller 调用方 Action 标识与声明上下文
74
+ * @param target 目标 Action 标识
75
+ * @param graph 可选的包依赖拓扑图
76
+ * @returns 若鉴权未通过返回标准 RuntimeError,通过则返回 undefined
77
+ */
78
+ checkUsesAuthorization(caller, target, graph) {
79
+ // 同包调用完全自由开放,不作限制
80
+ if (!caller.packageId || !target.packageId || caller.packageId === target.packageId) {
81
+ return undefined;
82
+ }
83
+ const targetRef = `${target.packageId}/${target.actionId}`;
84
+ const callerNode = graph?.getNode(caller.packageId);
85
+ const shortActionId = caller.actionId.includes("/")
86
+ ? caller.actionId.split("/").pop()
87
+ : caller.actionId;
88
+ const usesList = caller.declaredUses ||
89
+ callerNode?.manifest?.actions?.[shortActionId]?.uses ||
90
+ callerNode?.manifest?.actions?.[caller.actionId]?.uses ||
91
+ [];
92
+ const isAllowed = graph
93
+ ? graph.canCascadeCall(caller.packageId, caller.actionId, target.packageId, target.actionId)
94
+ : usesList.some((u) => isUsesDeclared(u, target.packageId, target.actionId));
95
+ if (!isAllowed) {
96
+ return {
97
+ code: UNDECLARED_ACTION_DEPENDENCY,
98
+ message: `Undeclared cross-package dependency: Action '${caller.packageId}/${caller.actionId}' does not declare dependency on '${targetRef}' in 'uses'`,
99
+ details: {
100
+ caller: `${caller.packageId}/${caller.actionId}`,
101
+ target: targetRef,
102
+ declaredUses: usesList,
103
+ },
104
+ };
105
+ }
106
+ return undefined;
107
+ }
108
+ /**
109
+ * 调用嵌套最大深度限制校验(Max Call Depth Policy)。
110
+ *
111
+ * 超限时返回标准 ACTION_CALL_CYCLE 错误。
112
+ *
113
+ * @param callStack 当前已累积的调用栈切片
114
+ * @param targetActionId 欲调用的目标 Action 标识
115
+ * @param maxDepthOverride 临时执行覆盖的最大深度限制
116
+ * @returns 超限错误或 undefined
117
+ */
118
+ checkCallDepth(callStack, targetActionId, maxDepthOverride) {
119
+ const limit = maxDepthOverride ?? this.maxCallDepth;
120
+ if (callStack.length >= limit) {
121
+ return {
122
+ code: ACTION_CALL_CYCLE,
123
+ message: `Maximum call depth of ${limit} exceeded: ${callStack.join(" -> ")} -> ${targetActionId}`,
124
+ details: {
125
+ reason: "depth_exceeded",
126
+ maxDepth: limit,
127
+ callStack: [...callStack],
128
+ },
129
+ };
130
+ }
131
+ return undefined;
132
+ }
133
+ /**
134
+ * 调用链环路死锁检测(Cycle Detection Policy)。
135
+ *
136
+ * 计算目标调用键并在历史调用栈中执行检测,杜绝 A -> B -> A 形成死锁。
137
+ * 命中环路时返回 ACTION_CALL_CYCLE 错误。
138
+ *
139
+ * @param callStack 当前已累积的调用栈切片
140
+ * @param targetActionId 欲调用的目标 Action 标识
141
+ * @param targetPackageId 目标 Action 所属包标识
142
+ * @param currentPackageId 当前执行发起方包标识
143
+ * @returns 包含规范化 callKey 与可选错误的结构体
144
+ */
145
+ checkCycle(callStack, targetActionId, targetPackageId, currentPackageId) {
146
+ const isExternal = Boolean(targetPackageId && currentPackageId && targetPackageId !== currentPackageId);
147
+ const callKey = targetPackageId
148
+ ? `${targetPackageId}/${targetActionId}`
149
+ : targetActionId;
150
+ let hasCycle = false;
151
+ if (isExternal) {
152
+ hasCycle = callStack.includes(callKey);
153
+ }
154
+ else {
155
+ hasCycle =
156
+ callStack.includes(callKey) ||
157
+ callStack.includes(targetActionId) ||
158
+ (targetPackageId ? callStack.includes(`${targetPackageId}/${targetActionId}`) : false);
159
+ }
160
+ if (hasCycle) {
161
+ return {
162
+ callKey,
163
+ error: {
164
+ code: ACTION_CALL_CYCLE,
165
+ message: `Cycle detected in action invocation: ${callStack.join(" -> ")} -> ${callKey}`,
166
+ details: {
167
+ reason: "cycle_detected",
168
+ callStack: [...callStack],
169
+ target: callKey,
170
+ },
171
+ },
172
+ };
173
+ }
174
+ return { callKey };
175
+ }
176
+ /**
177
+ * 并发活跃子任务配额检查(Sub-Run Quota Policy)。
178
+ *
179
+ * 针对同源 rootRunId 限制派生的并发子任务上限,防止资源耗尽。
180
+ *
181
+ * @param rootRunId 根运行标识符
182
+ * @returns 超限错误或 undefined
183
+ */
184
+ checkSubRunQuota(rootRunId) {
185
+ const current = this.activeSubRunsPerRoot.get(rootRunId) || 0;
186
+ if (current >= this.maxSubRuns) {
187
+ return {
188
+ code: ACTION_SUBRUN_LIMIT,
189
+ message: `Maximum concurrent sub-runs (${this.maxSubRuns}) reached for root run '${rootRunId}'`,
190
+ details: {
191
+ limit: this.maxSubRuns,
192
+ },
193
+ };
194
+ }
195
+ return undefined;
196
+ }
197
+ /**
198
+ * 申请子任务并发配额槽位。
199
+ *
200
+ * @param rootRunId 根运行标识符
201
+ * @returns 是否成功获取槽位(若已达上限返回 false)
202
+ */
203
+ acquireSubRun(rootRunId) {
204
+ const current = this.activeSubRunsPerRoot.get(rootRunId) || 0;
205
+ if (current >= this.maxSubRuns) {
206
+ return false;
207
+ }
208
+ this.activeSubRunsPerRoot.set(rootRunId, current + 1);
209
+ return true;
210
+ }
211
+ /**
212
+ * 释放已申请的子任务并发配额槽位。
213
+ *
214
+ * @param rootRunId 根运行标识符
215
+ */
216
+ releaseSubRun(rootRunId) {
217
+ const current = this.activeSubRunsPerRoot.get(rootRunId) || 1;
218
+ if (current <= 1) {
219
+ this.activeSubRunsPerRoot.delete(rootRunId);
220
+ }
221
+ else {
222
+ this.activeSubRunsPerRoot.set(rootRunId, current - 1);
223
+ }
224
+ }
225
+ /**
226
+ * 获取指定根运行当前的活跃并发子任务计数。
227
+ */
228
+ getActiveSubRuns(rootRunId) {
229
+ return this.activeSubRunsPerRoot.get(rootRunId) || 0;
230
+ }
231
+ }
@@ -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
  }